【发布时间】:2017-06-13 10:01:29
【问题描述】:
错误:
遇到 PHP 错误严重性:通知
- 消息:未定义变量:calificacione
- 消息:为 foreach() 提供的参数无效
- 怎么了?
- 在
Controller中创建变量:$data['calificacione'] - 并在视图中调用
foreach
我的观点:
<table class="table table-condensed table-striped">
<thead>
<tr>
<th>Calificacione</th>
</tr>
</thead>
<tbody>
<?php
foreach ($calificacione as $key => $value) {
echo "<pre>";print_r($value);echo "</pre>";
}
?>
<tr>
<td><?php ?></td>
</tr>
<?php } ?>
</tbody>
</table>
我的控制器
class Provedore extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->model(['Provedore_model','Provedor_calificacione_model','Provedor_calificacione_model','Personas_contato_model','Direcione_model']);
}
/*
* Listing of all provedores
*/
function index()
{
$data['provedores'] = $this->Provedore_model->get_all_provedores();
$data['calificacione'] = $this->Provedor_calificacione_model->get_all_provedor_calificaciones();
$data['_view'] = 'provedore/index';
$this->load->fullView('layouts/main',$data);
}
【问题讨论】:
-
不是将数据作为第二个参数传递,而是在加载视图之前加载变量:
$this->load->vars($data); $this->load->fullView('layouts/main');。试试这样。 (也检查here。)
标签: codeigniter controller views