我在项目中使用MVC模式,我想在项目中完美地实现MVC,没有任何循环漏洞。我有以下情况我的申请,
foreach($std_results as $std_result)
{
$std_name = ORM::factory('students')->where('id',$std_result->hall_ticket_number);//I want to avoid this
//other stuff follows from here
}
我展示的上述代码来自视图,我已经根据控制器中的一些条件提取了总记录,并将结果传递给视图,在那里我再次遇到了一种情况,我想根据获得的记录与模型通信。我甚至不想在那里调用模型层函数,我该如何避免这种情况,我在应用程序中使用Kohana框架。提前感谢您的帮助。
1)您需要为学生提供一个模型类:
class Student extends ORM
{
public function your_function()
{
// Do the DB stuff here
}
}
2) 从控制器调用方法并将结果传递给视图:
// ...
$std_results = ORM::factory('student')->your_function();
// ...
$view->bind('std_results', $std_results);
// ...