将查询+额外变量从模型传递到视图

时间:2015-11-11 21:48:01

标签: php codeigniter

我想知道将查询结果+一个单独的文本从模型传递到视图的最佳方法是什么。

我的模特

    $query = $this->db->query("SELECT * from ci_wizard_results WHERE `tblresultrequestsource` LIKE '%".$countryqueryresult->countrytld."%' AND tblresultkioskname = '' ".$sqlkioskfilter." ORDER BY ci_wizard_results.tblresultdatetime DESC");
    $querytext = "some text"
    return $query->result();

控制器:

$data['yunbe_selectall'] = $this->wizard_model->yunbe_selectall();

查看:



<?php foreach($yunbe_selectall as $yunbe_selectallrow) { ?>
						<tr>
								<td><?php echo $yunbe_selectallrow->tblresultrefid;?></td>
								<td><?php echo $yunbe_selectallrow->tblresultdatetime;?></td>
								<td><?php echo $yunbe_selectallrow->tblresultip;?></td>
								<td><?php echo $yunbe_selectallrow->tblresultrequestsource;?></td>
&#13;
&#13;
&#13;

我想显示&#34; $ querytext&#34;进入视野。我知道将每个返回放在不同的函数中会更好,但由于函数中有一些复杂的查询来获得结果,我想避免复制它。

我尝试将其作为数组传递,但我无法将其显示出来。

谢谢!

1 个答案:

答案 0 :(得分:1)

你在一个阵列的正确轨道上:

query = $this->db->query("SELECT * from ci_wizard_results WHERE `tblresultrequestsource` LIKE '%".$countryqueryresult->countrytld."%' AND tblresultkioskname = '' ".$sqlkioskfilter." ORDER BY ci_wizard_results.tblresultdatetime DESC");
$querytext = "some text"
return array('text'=>$querytext, 'result'=>$query->result());

控制器:

$data['yunbe_selectall'] = $this->wizard_model->yunbe_selectall();

查看:

<h2><?php echo $yunbe_selectall['text'];?></h2>
<?php foreach($yunbe_selectall['result'] as $yunbe_selectallrow) { ?>