代码点火器上的模型视图控制器项目 - 无法使用活动记录类将数据插入表中。
错误
遇到PHP错误
严重性:注意
消息:未定义的属性:Store :: $ Storemdl
文件名:controllers / Store.php
行号:49
回溯:
文件:C:\ xampp \ htdocs \ ci \ application \ controllers \ Store.php 行:49 功能:_error_handler
文件:C:\ xampp \ htdocs \ ci \ index.php 行:292 功能:require_once
致命错误:在第49行的C:\ xampp \ htdocs \ ci \ application \ controllers \ Store.php中的非对象上调用成员函数signupchk()
遇到PHP错误
严重性:错误
消息:在非对象上调用成员函数signupchk()
文件名:controllers / Store.php
行号:49
回溯:
MODEL
<?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;
}
} ?>
CONTROLLER
<?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();
}
}
?>
答案 0 :(得分:0)
发布模型类的代码,并在您的模型中更改此
$this->db->where('username,$username');
到
$this->db->where('username',$username);
or
$this->db->where("username,$username");// single quote to double quote
在函数signupchk($username)
答案 1 :(得分:0)
你的模特班在哪里?你可以试试这个:
<?PHP
defined('BASEPATH') OR exit('No direct script access allowed');
class Your_model_name extends CI_Model{
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;
}
}
}
?>
答案 2 :(得分:0)
您忘了加载模型。 在插入函数中添加以下行:
$这 - &GT;负载&GT;模型(&#39; Storemdl&#39);