未定义的变量CodeIgniter?

Tom*_*one 0 php mysql codeigniter

我的php有问题.我一直在使用codeigniter,以下代码返回给我这个错误消息:

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: item
Filename: views/banner.php
Line Number: 37
Run Code Online (Sandbox Code Playgroud)

我的控制器如下:

public function __construct()
{
    parent::__construct();

    $this->auth->check();

    $this->load->database();
    $this->load->helper('url');
    $this->load->model('banner_model');
}

public function index()
{
    $dados['banner'] = $this->banner_model->recuperar_todos_banners();

    $this->load_view("banner", $dados);
}
Run Code Online (Sandbox Code Playgroud)

我的看法:

    <? foreach ($banner as $item):?>
       <tr>
          <td><?=$item->chave?></td>
          <td><?=$item->imagem?></td>
          <td><?=$item->descricao?></td>
          <td><?=$item->link?></td>
          <td>
             <button type="button" class="btn btn-danger btn-xs">
                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
             </button>
          </td>
       </tr>
    <? endforeach; ?>
Run Code Online (Sandbox Code Playgroud)

我使用var_dump测试了两个变量.此代码的目的是访问MySQL数据库并将结果存储在数组中.$ banner变量工作正常,所有数据都在那里,因此每个位置都被对象占用,每个对象都是一个表行.

我知道之前在StackOverflow上已经问过这个问题,但我仍然无法弄清楚到底发生了什么.

Fun*_*ner 6

我:

是否启用了短标签?如果不是,那就做<?php echo而不是做<?=同样的<?事情<?php- 弗雷德-ii- 23分钟前"

OP:

抱歉.你是对的.我只修复了一些标签并忘了其他标签. - TomásDornasPerone"

毕竟问题确实是短标签.

以及Vickel的评论,我引述:

使用<?php foreach ?> <?php endforeach;?>- Vickel 4分钟前"