[英]Codeigniter loading two different data array from a database with the second one is dependent with the first one and load into a view
This is my code: 这是我的代码:
my model : My_model
我的模型: My_model
function load_modules(){
$modules = $this->db->query('SELECT name FROM module');
$result = $modules->result_array();
return $result;
}
function load_lesson($modname){
$lessons = $this->db->query(
'SELECT lesson.name
FROM lesson
INNER JOIN module
ON module.id = lesson.moduleid and module.name = $modname'
);
$result = $lessons->result_array();
return $result;
}
my controller : My_controller
我的控制器: My_controller
$this->load->model('My_model');
$arraydata['values'] = $this->My_model->load_modules();
and in my view: 在我看来:
foreach($values as $modulename){
load_lesson($modulename); // This is the method from my model which
// I want to be access in my controller in a way that will work like this.
}
What I wanted to happen is to be able to get all lessons for each module. 我想做的是能够获得每个模块的所有课程。 But I can't figure out of a way to do it in a controller.
但是我想不通在控制器中做到这一点的方法。 Hope you can help me with this.
希望你能帮我这个忙。 Thanks!
谢谢!
don't try to call a method of a model from a view. 不要试图从视图中调用模型的方法。 try something like this in controller....
在控制器中尝试这样的事情。
$this->load->model('My_model');
$arraydata['values'] = $this->My_model->load_modules();
foreach($arraydata['values'] as $key=>$value){
$arraydata['values'][$key]['lessons']=$this->My_model->load_lesson($value);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.