模型視圖控制器項目上的代碼點火器 - 無法使用活動記錄類插入數據到表中。如何使用codeigniter Active Record查詢將數據插入表中?
錯誤
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Store::$Storemdl
Filename: controllers/Store.php
Line Number: 49
Backtrace:
File: C:\xampp\htdocs\ci\application\controllers\Store.php Line: 49 Function: _error_handler
File: C:\xampp\htdocs\ci\index.php Line: 292 Function: require_once
Fatal error: Call to a member function signupchk() on a non-object in C:\xampp\htdocs\ci\application\controllers\Store.php on line 49
A PHP Error was encountered
Severity: Error
Message: Call to a member function signupchk() on a non-object
Filename: controllers/Store.php
Line Number: 49
Backtrace:
模型
<?PHP
defined('BASEPATH') OR exit('No direct script access allowed');
function __construct()
{
parent ::__construct();
$this->load->database();
}
function signupchk($username)
{
$this->db->select('username');
$this->db->from('users');
$this->db->where('username,$username');
$sql = $this->db->get();
if($sql && $sql->num_rows() > 0)
{
return false;
}
else
{
return true;
}
}
function signup($data)
{
$data = array(
'rusername'=> 'username',
'rpassword'=> 'password',
'remail' => 'email',
'rphone' => 'phone',
'rgender' => 'gender',
'rqualify' => 'qualification',
);
$sql = $this->db->insert('users',$data);
return $sql;
}
} ?>
控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Store extends CI_Controller
{
function index()
{
$this->load->view('home');
}
function login()
{
$this->load->view('login');
}
function signup()
{
$this->load->view('signup');
}
function inserttbl(){
$username = $this->input->post('username');
$rslt = $this->Storemdl->signupchk($username);
if($result){
$this->Storemdl->signup($this->input->post());
}
else
{
echo "username already exists";
}
$this->index();
}
}
?>
爲什麼使用$ this-> Storemdl-> signupchk();你在配置文件 –