“codeigniter 3视图中未定义的变量”

huangapple go评论43阅读模式
英文:

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)

&lt;div class=&quot;row&quot;&gt;
			&lt;? 
			if ($articles){
			 foreach ($articles as $article):?&gt;
                &lt;div class=&quot;col-sm-4 col-lg-3&quot;&gt;
                    &lt;div class=&quot;category-item wow fadeInUp&quot; data-wow-delay=&quot;.3s&quot;&gt;
                        &lt;i class=&quot;&lt;?=$article-&gt;title?&gt;&quot;&lt;/i&gt;
                        &lt;a href=&quot;#&quot;&gt;&quot;&lt;?=$article-&gt;description?&gt;&quot;&lt;/a&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
			&lt;? endforeach:}?&gt;
            &lt;/div&gt;

My controller

 public function index()
    {
         $data = array();
		 $data[&#39;articles&#39;] = $this-&gt;main_model-&gt;get_table_data(&#39;masari_sectors&#39;,          array(), 5, &#39;ID&#39;,&#39;desc&#39;);
		 
		 $this-&gt;load-&gt;view(&#39;site/body&#39;, $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.

英文:
&lt;div class=&quot;row&quot;&gt;
        &lt;? 
        if ($articles){
         foreach ($articles as $article)
        { ?&gt;
            &lt;div class=&quot;col-sm-4 col-lg-3&quot;&gt;
                &lt;div class=&quot;category-item wow fadeInUp&quot; data-wow-delay=&quot;.3s&quot;&gt;
                    &lt;i class=&quot;&lt;?=$article-&gt;title?&gt;&quot;&lt;/i&gt;
                    &lt;a href=&quot;#&quot;&gt;&quot;&lt;?=$article-&gt;description?&gt;&quot;&lt;/a&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;?php } } ?&gt;
        &lt;/div&gt;




public function index()
{
     $data = array();
     $data[&#39;articles&#39;] = $articles = $this-&gt;main_model-&gt;get_table_data(&#39;masari_sectors&#39;,          array(), 5, &#39;ID&#39;,&#39;desc&#39;);
     $data[&#39;articles&#39;] = $articles;
     $this-&gt;load-&gt;view(&#39;site/body&#39;, $data);
     
     
}

huangapple
  • 本文由 发表于 2023年6月15日 06:20:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76477929.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定