本文介绍了从控制器传递数组到视图-Codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在控制器中打印数组,然后将其传递给视图,这就是输出
I tried to print the array in the controller, before passing it to a view and this is the output
Array ( [annunci] => Array ( [0] => stdClass Object ( [EmailDatore] => [email protected] [Nome] => asdasd [Cognome] => asdas [IdAnnuncio] => 9 [Titolo] => sfsdfdsfshrea [Testo] => agrefdgdagdfg [Categoria] => [Sede] => [TipoContratto] => [Add_Date] => [Drop_Date] => )
[1] => stdClass Object ( [EmailDatore] => [email protected] [Nome] => asdasd [Cognome] => asdas [IdAnnuncio] => 10 [Titolo] => fafa [Testo] => fafaerea asdasdas dafasfd [Categoria] => [Sede] => [TipoContratto] => [Add_Date] => [Drop_Date] => ) ) )
我从主控制器中的此方法获取数组
I get the array from this method in my maincontroller
public function get_annunci(){
$query=$this->user_model->annunci($this->email);
print_r($query);
}
我想将此数组传递给视图,然后读取数据.所以我这样重写我的方法
I would like to pass this array to a view and then read the data. So i rewrite my method like this
public function get_annunci(){
$query=$this->user_model->annunci($this->email);
$this->load->view('main_view',$query);
}
在主视图中,我有这个
<div class="tab-pane active" id="annunci">
<ul>
<?php
print_r($annunci);
?>
</ul>
</div>
这是我的错误
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: annunci
Filename: views/tab_annunci_view.php
Line Number: 4
推荐答案
public function get_annunci(){
$query['annunci']=$this->user_model->annunci($this->email);
$this->load->view('main_view',$query);
}
您正在传递数组,但没有将anunci作为变量传递.
You're passing the array but you aren't passing annunci as a variable.
这篇关于从控制器传递数组到视图-Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!