![](/img/trans.png)
[英]Codeigniter Getting data from two different models and show in one view
[英]Codeigniter loading two different data array from a database with the second one is dependent with the first one and load into a view
這是我的代碼:
我的模型: 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
$this->load->model('My_model');
$arraydata['values'] = $this->My_model->load_modules();
在我看來:
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.
}
我想做的是能夠獲得每個模塊的所有課程。 但是我想不通在控制器中做到這一點的方法。 希望你能幫我這個忙。 謝謝!
不要試圖從視圖中調用模型的方法。 在控制器中嘗試這樣的事情。
$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.