Error:
A PHP Error was encountered笨:查看的foreach呼叫控制器Severity: Notice
- Message: Undefined variable: calificacione
- Message: Invalid argument supplied for 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);
}
而是将数据作为第二个参数,加载视图进行负载变量:' $这 - >负载>瓦尔($数据); $这 - >负载> fullView( '布局/主');'。尝试这种方式。 (检查[这里](https://www.codeigniter.com/user_guide/libraries/loader.html#CI_Loader::vars)也是如此。) – Tpojka