CodeIgniter当我调用函数模型时未定义的属性 [英] CodeIgniter Undefined property when I call the function model
本文介绍了CodeIgniter当我调用函数模型时未定义的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请我需要帮助,我从1天前寻找错误
严重性:Notice
消息:Undefined属性:Login :: $ Usuario_model
文件名:api / login.php
行号:27
致命错误:调用成员函数obtener_usuario非对象在/home/fpincheira/web/cobranza/application/controllers/api/login.php第27行
这是我的模型 usuario_model.php 。这个查询是一个例子,我真正的查询是其他
<?php
class Usuario_model extends CI_Model {
function __construct(){
parent :: __ construct();
$ this-> db1 = $ this-> load-> database('db1',TRUE);
}
function obtener_usuario($ rut){
$ sql =SELECT sysdate FROM dual; // this is a example query
$ query = $ this-> db1-> query($ sql,array($ rut));
return $ query-> result_array();
}
}
?>
控制器 login.php
<?php defined('BASEPATH')OR exit('不允许直接脚本访问);
require APPPATH。'/ libraries / REST_Controller.php';
class Login extends REST_Controller {
function __construct(){
parent :: __ construct();
}
function validarUsuario_post(){
try {
$ username = $ this-> post('user');
$ this-> load-> model('Usuario_model','usuario');
$ perfil_usuario = $ this-> usuario-> obtener_usuario($ username);
// print_r($ perfil_usuario);
} catch(Exception $ e){
$ this-> response(array('error'=> $ e-> getMessage()),$ e-> getCode ;
}
}
}
?>
在我的 autoload.php 中加载了'database' / p>
您能看到错误吗?
解决方案
/ p>
我不得不创建对象,因为导入模型codeigniter没有创建实例对象。
$ this-> load-> model('usuario_model');
$ usuario = new usuario_model();
$ perfil_usuario = $ usuario-> obtener_usuario($ username);
这种方式我可以访问模型的功能。
如果有人有最好的答案,请发表评论,谢谢
尊敬
please I need help, I'm looking for the mistake from 1 day ago
Severity: Notice
Message: Undefined property: Login::$Usuario_model
Filename: api/login.php
Line Number: 27
Fatal error: Call to a member function obtener_usuario() on a non-object in /home/fpincheira/web/cobranza/application/controllers/api/login.php on line 27
this is my model usuario_model.php. This query is a example, my real query is other
<?php
class Usuario_model extends CI_Model {
function __construct(){
parent::__construct();
$this->db1 = $this->load->database('db1', TRUE);
}
function obtener_usuario($rut){
$sql = "SELECT sysdate FROM dual"; //this is a example query
$query = $this->db1->query($sql, array($rut));
return $query->result_array();
}
}
?>
The controller login.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH.'/libraries/REST_Controller.php';
class Login extends REST_Controller {
function __construct(){
parent::__construct();
}
function validarUsuario_post(){
try{
$username = $this->post('user');
$this->load->model('Usuario_model','usuario');
$perfil_usuario = $this->usuario->obtener_usuario($username);
//print_r($perfil_usuario);
}catch(Exception $e){
$this->response(array('error'=>$e->getMessage()), $e->getCode());
}
}
}
?>
In my autoload.php I have loaded 'database' library.
Can you see the mistake?
解决方案
answer the question.
I had to create the object, because to import the model codeigniter not create the instance the object.
$this->load->model('usuario_model');
$usuario = new usuario_model();
$perfil_usuario = $usuario->obtener_usuario($username);
this way I could access to function of model.
If somebody have a best answer, pliss comment, thanks
Regards
这篇关于CodeIgniter当我调用函数模型时未定义的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文