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