无法从代码点火器中的控制器页连接模型页



这是我的数据库php页面

$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn'   => '',
'hostname' => '192.168.1.200',
'username' => 'name',
'password' => 'password',
'database' => 'codeignter_tutorial',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

我无法从控制器页面加载模型页面。这是我的错误,如果能得到任何帮助,我们将不胜感激

致命错误:在第16行调用/var/www/html/bcit-CI-CodeIgniter-3.1.11-0-gb73eb19/bcit-CI-CodeIgniter-b73eb19/application/controllers/Welcome.php中未定义的方法CI_Loader::models((遇到PHP错误严重性:错误

消息:调用未定义的方法CI_Loader::models((文件名:controllers/Welcome.php行号:16回溯:

这是我的控制器页面欢迎使用.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {

public function index()
{
$this->load->view('dashboard');
}
public function __construct()
{
parent::__construct();
$this->load->helper(array("form","url"));
$this->load->models('models');

}
public function login()
{
$this->load->view('loginPage');
}
public function dashboard()
{
$data['name']=$this->input->post('name');
$data['age']=$this->input->post('age');
$this->models->dbdata($data);

}
}
?>

这是我的模型页面models.php

<?php
class models extends CI_model
{
public function dbdata($inserttodb)
{
$this->db->insert("registration",$inserttodb);
return $var->result_array();
}
}
?>

在模型页面中,模型的"m"应为大写

class **M**odels extends CI_model

在控制页面

this->load->model('models');

这就是从控制器加载模型的方式:

public function __construct()
{
parent::__construct();
$this->load->model('models', 'your_model'); //use 'your_model' to reference your model
}

这就是你对你的模型的称呼:

$this->your_model->dbdata($data); 
//'your_model' is from constructor, 'dbdata' is the name of your function in model

然后确保该方法接受"数据":

public function dbdata($data)
{
//your code goes here
}

最新更新