在Codeigniter中的视图内部起作用 [英] function inside a view in codeigniter
本文介绍了在Codeigniter中的视图内部起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 ci
的新手,有人可以帮助我或在我的代码和最佳实践中提供一些建议吗?我有一个 foreach
语句,该语句要求使用一个函数来显示大量数据。这是我的示例代码。
预先感谢
i'm a newbie in ci
, can anyone help me or give some suggestions in my code and best practice? i have a foreach
statement that require to use a function for displaying a huge data. here's my sample code of view.
Thank you in advance
foreach($data->result() as $d){
if($d->condi){
$sample = myfunction($d->value1, $d->value2, $value->3);
}
else{
$d->otherdisplay;
if($d->condition2){
$sample = myfunction($d->value1, $d->value2, $value->3);
}
}
}
function myfunction($a,$b,$c){
/*do something;*/
}
推荐答案
这取决于方法
应该放在控制器
或库
中,这取决于您的方法是否可以从浏览器调用
。
it depends , anyway these kind of methods
should be in controllers
or in libraries
, it depends if your method can be called from browser or not
.
如果要使用某种方法,需要使常规操作
使用
If you want to use some method that you need to makesome routine action
use a
library or an helper
如果要使用网页方法
,请在控制器
Model = SQL and db stuffs
Controller = all the php stuffs + data returned from Model
View = html/js + data returned from Controller
Check How to create Own libraries in CI
这篇关于在Codeigniter中的视图内部起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文