這是我的控制器:我的模型並沒有在控制器加載笨
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('User_model');
$this->load->helper(array('form','text','url','array'));
$this->load->library(array('Form_validation','email','session'));
}
public function index()
{
$this->model->insert_item();
$this->load->view('welcome_message');
}
}
這是我的模型:
defined('BASEPATH') OR exit('No direct script access allowed');
class User_model extends CI_Model {
public function insert_item()
{
echo "hi";
}
}
當我調用模型的功能,但它不會加載它秀錯誤致命錯誤:調用非對象上的成員函數insert_item()
請記住,我們只使用模型來做數據庫操作, – Ukasyah
@Ukasyah - 事實並非如此。您可以將模型用於任何數據處理情況(如從xml或json中檢索數據)。 – shaggy