CodeIgniter调用模型在视图? [英] CodeIgniter calling model on view?

查看:115
本文介绍了CodeIgniter调用模型在视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,其中包含一个数据表,这个数据是在模型上生成的。
如何调用我的视图中的这个模型发布在我的视图...?
这是我想对php上的codeIgniter做的等效:

  while($ row = mysql_fetch_array requet))
{
//显示我的数据的代码;
}


解决方案

请尝试使用
$ CI =& get_instance()



然后按如下方式加载您的模型:



$ CI-> load-> model('someModel')



p>

$ result = $ CI-> someModel-> somefunction()



然后使用foreach显示



foreach($ result as $ row){$ row-> somecolumnName}


I have a view which comport a table of data, this data is generated on a model. How can I call this model in my view to be posted on my view...? That's the Equivalent of what I want to do with codeIgniter on php :

while($row = mysql_fetch_array($requet))
      {
// code of displaying my data;
      }

解决方案

try using $CI =& get_instance()

then load your model like this:

$CI->load->model('someModel')

then call your model function like this:

$result = $CI->someModel->somefunction()

then display using foreach

foreach($result as $row){ $row->somecolumnName }

这篇关于CodeIgniter调用模型在视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆