0
經建立,企圖從我的數據庫獲取數據,我的模型,視圖和控制器我收到一個錯誤,並希望幫助找出爲什麼我收到此錯誤:問題從數據庫中獲取數據笨
的錯誤是如下:
Severity: Notice
Message: Undefined property: How_can_we_help::$Content_model
Filename: controllers/how_can_we_help.php
Line Number: 14
我試圖在我的模型調用一個函數來獲取我的數據,控制器是這樣的:
class How_can_we_help extends CI_Controller {
public function index()
{
//subcategory of page
$data = array(
'subcategory' => 'how_can_we_help',
);
//Get data from content table where subcategory = subcategory
$data['pagecontent'] = $this->Content_model->getContent($data);
//inserts "how_can_we_help" view into template
$data['main_content'] = 'how_can_we_help';
$this->load->view('includes/template', $data);
}
}
我只想檢索數據wher E中的子類= how_can_we_help
型號:
class Content_model extends CI_Model {
function getContent($data){
$this->db->select('category, subcategory, title, intro, content, tags');
$this->db->from('content');
$this->db->where($data);
$query = $this->db->get();
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
}
}
最後認爲
<?php
foreach ($pagecontent->result() as $row)
{
$title = $row->title;
$intro = $row->intro;
$content = $row->content;
$tags = $row->tags;
}
;?>
可能有人好心告訴我的我的方式錯誤。
蝙蝠俠
當然,我沒有.....(aarrggghh ....)*劉海頭在牆上*謝謝達米安! – hairynuggets