0

我在我的项目中使用 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 框架。提前感谢您的帮助。

4

1 回答 1

1

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);
// ...
于 2012-08-26T08:39:50.193 回答