英文:
codeigniter 3 undefined variable in view
问题
我在视图上收到错误消息(未定义变量“article”)
<div class="row">
<?
if ($articles){
foreach ($articles as $article):?>
<div class="col-sm-4 col-lg-3">
<div class="category-item wow fadeInUp" data-wow-delay=".3s">
<i class="<?=$article->title?>"></i>
<a href="#"><?=$article->description?></a>
</div>
</div>
<?endforeach;}?>
</div>
我的控制器
public function index()
{
$data = array();
$data['articles'] = $this->main_model->get_table_data('masari_sectors', array(), 5, 'ID', 'desc');
$this->load->view('site/body', $data);
}
请帮忙,谢谢。您的文字。
解决我的问题并学习如何修复。
英文:
I am getting error message on view (undefined variable article)
<div class="row">
<?
if ($articles){
foreach ($articles as $article):?>
<div class="col-sm-4 col-lg-3">
<div class="category-item wow fadeInUp" data-wow-delay=".3s">
<i class="<?=$article->title?>"</i>
<a href="#">"<?=$article->description?>"</a>
</div>
</div>
<? endforeach:}?>
</div>
My controller
public function index()
{
$data = array();
$data['articles'] = $this->main_model->get_table_data('masari_sectors', array(), 5, 'ID','desc');
$this->load->view('site/body', $data);
}
Please help
Thanksyour text
Resolve my issues and learn how to fix that
答案1
得分: 1
Sure, here is the translated code snippet:
<div class="row">
<?php
if ($articles){
foreach ($articles as $article)
{ ?>
<div class="col-sm-4 col-lg-3">
<div class="category-item wow fadeInUp" data-wow-delay=".3s">
<i class="<?=$article->title?>"></i>
<a href="#"><?=$article->description?></a>
</div>
</div>
<?php } } ?>
</div>
public function index()
{
$data = array();
$data['articles'] = $articles = $this->main_model->get_table_data('masari_sectors', array(), 5, 'ID', 'desc');
$data['articles'] = $articles;
$this->load->view('site/body', $data);
}
Please note that I've translated the HTML and PHP code, but I haven't provided any additional content.
英文:
<div class="row">
<?
if ($articles){
foreach ($articles as $article)
{ ?>
<div class="col-sm-4 col-lg-3">
<div class="category-item wow fadeInUp" data-wow-delay=".3s">
<i class="<?=$article->title?>"</i>
<a href="#">"<?=$article->description?>"</a>
</div>
</div>
<?php } } ?>
</div>
public function index()
{
$data = array();
$data['articles'] = $articles = $this->main_model->get_table_data('masari_sectors', array(), 5, 'ID','desc');
$data['articles'] = $articles;
$this->load->view('site/body', $data);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论