我是 ci
的新手,任何人都可以帮助我或对我的代码和最佳实践提出一些建议吗?我有一个 foreach
语句,它需要使用一个函数来显示大量数据。这是我的示例代码。
提前谢谢你
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;*/
}
最佳答案
这取决于,无论如何这些方法
应该在controllers
或libraries
中,这取决于你的方法是否可以是否从浏览器调用
。
如果你想使用一些你需要做一些routine action
的方法,使用一个
library or an helper
如果您想使用网页方法
,请在controller
中使用它
Model = SQL and db stuffs
Controller = all the php stuffs + data returned from Model
View = html/js + data returned from Controller
关于php - 在 codeigniter 的 View 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15807145/