2017-06-13 70 views
0

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); 
} 
+0

而是將數據作爲第二個參數,加載視圖進行負載變量:' $這 - >負載>瓦爾($數據); $這 - >負載> fullView( '佈局/主');'。嘗試這種方式。 (檢查[這裏](https://www.codeigniter.com/user_guide/libraries/loader.html#CI_Loader::vars)也是如此。) – Tpojka

回答

0

請查看以下上述可能性。

您是從模型或任何錯誤獲取數據。

var_dump($data['calificacione']); 
die; 
$data['_view'] = 'provedore/index'; 
$this->load->fullView('layouts/main',$data); 

請分享您的輸出,以便我們爲您提供幫助。

-1
//try this 

function index() 
{ 
$provedores = $this->Provedore_model->get_all_provedores(); 
$data['provedores'] = $provedores; 
$calificacione = $this->Provedor_calificacione_model->get_all_provedor_calificaciones(); 
    $data['calificacione'] = $calificacione; 
$this->load->view('layouts/main',$data) 
$this->load->view('provedore/index',$data) 
} 
+0

同樣的錯誤繼續 –

+0

相同的錯誤信息顯示你以前得到。@ cristian馬克斯。 – Anurag

0
在模型

Provedore_modelget_all_provedores可能有一個像

function get_all_provedores ($argument) 
{ 
// your database query 
} 

一些參數,你did'nt履行這一說法