• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
the model does not connect

#1
I am using the latest version of Codeigniter, the NetBeans program for the code and XAMPP.

In the controller I have the following code (it's called Sesion.php): 
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Sesion extends CI_Controller {

     public function 
__construct() {
 
       parent::__construct();
 
       $this->load->helper('url');
 
       $this->load->library('session');
 
       $this->load->model('usuario');
 
       
        
    
}
    public function 
index()
    {
 
            if (!$this->input->post()) {  //SI NO HAY POST  
 
           $cuerpo['c1'] = $this->load->view('form_sesion'''true); //CARGA LA VISTA
 
           $this->load->view('plantilla', array('cuerpo' => $cuerpo));
 
       } else { //SI HAY POST 
 
            $usuario $this->usuario->ExisteUsuario($this->input->post('user'), $this->input->post('pass'));
 
           //MIRAR SI EXISTE EL USUARIO DE QUE TIPO ES
 
           $this->Entrar($usuario); //MANDA A SU CONTROLADOR
 
       }


In the model (it's called Usuario.php): 
PHP Code:
<?php

class Usuario extends CI_Model{
 
   
    public 
function __construct() {
 
       parent::__construct();
 
   }

 
   
    public 
function ExisteUsario($user$pass){
 
       if($user === "usuario" && $pass == "admin") {
 
       return "vale";}
 
   }


The error:
PHP Code:
An uncaught Exception was encountered
Type
Error

Message
Call to undefined method Usuario::ExisteUsuario()

FilenameC:\xampp2\htdocs\matsa\application\controllers\Sesion.php

Line Number
24

Backtrace
:

FileC:\xampp2\htdocs\matsa\index.php
Line
315
Function: require_once 

Note: the function receives the two variables perfectly

I think that it should work but I do not know what happens, I hope you can help me. Regards!
Reply

#2
@adanwaky,

It might be that the name of the model needs to have a capital first letter.
Instead of $this->usuario->ExisteUsuario() it might need to be $this->Usuario->ExisteUsuario
also...
instead of $this->load->model('usuario'); it might need to be $this->load->model('Usuario');

The reason I say this is because in your error message it states that... Call to undefined method Usuario::ExisteUsuario()
DID you notice the capital first letter of the Model?

Also, any reason why you don't return a value of FALSE if the model function if condition is not completed? I always try to either return a value or FALSE from a model so that I will always know if it was successful or not.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.