gpt4 book ai didi

php - 将数组从 Controller 传递到 View - Codeigniter

转载 作者:行者123 更新时间:2023-12-05 00:19:27 25 4
gpt4 key购买 nike

我尝试在 Controller 中打印数组,然后将其传递给 View ,这是输出

Array ( [annunci] => Array ( [0] => stdClass Object ( [EmailDatore] => you@welcom.it [Nome] => asdasd [Cognome] => asdas [IdAnnuncio] => 9 [Titolo] => sfsdfdsfshrea [Testo] => agrefdgdagdfg [Categoria] => [Sede] => [TipoContratto] => [Add_Date] => [Drop_Date] => ) 
[1] => stdClass Object ( [EmailDatore] => you@welcom.it [Nome] => asdasd [Cognome] => asdas [IdAnnuncio] => 10 [Titolo] => fafa [Testo] => fafaerea asdasdas dafasfd [Categoria] => [Sede] => [TipoContratto] => [Add_Date] => [Drop_Date] => ) ) )

我在主 Controller 中从这个方法获取数组
 public function get_annunci(){


$query=$this->user_model->annunci($this->email);
print_r($query);
}

我想将此数组传递给 View ,然后读取数据。所以我像这样重写我的方法
public function get_annunci(){
$query=$this->user_model->annunci($this->email);
$this->load->view('main_view',$query);
}

在主要 View 中,我有这个
<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

最佳答案

这是因为您尚未定义 $annunci 并将其提供给 View 。您需要先将其加载到 View 中

Controller

$data['id'] = $yourArray;
$this->load->view('your_view_file', $data);

查看
 <?php print_r($id); ?> //prints $yourArray

关于php - 将数组从 Controller 传递到 View - Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13387729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com