CodeIgniter Forums

Full Version: How to show error messages from models?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Alhazred[/eluser]
I'm developing my first application using CI, from a controller I call a model, but at the call the application stops.
If I remove the model call the application goes on.
I'm sure to call the model in the correct way, because if I put a wrong name for it I get a message for an inexistent model.

The problem must be inside the model, but I don't get any error message, how do I find where the problem is?
I tried to put some echo as debug and then exit(), but they don't appear.
Is there something to do to show php errors from models?

El Forum

[eluser]Alhazred[/eluser]
I add some code because it looks the problem is not sure to be inside the model, I've left only the constructor inside it and the problem persists.

Controller
Code:
class Authentication extends CI_Controller
{
/**
  * Funzione di login
  * @return boolean true in caso di successo, false altrimenti
  */
public function login()
{
  //form validation
  $this->load->library('form_validation');
  $this->form_validation->set_rules('username', 'lang:form_username', 'required|alpha_dash');
  $this->form_validation->set_rules('password', 'lang:form_password', 'required');
  
  //caricamento file messaggi autenticazione
  $this->lang->load('authentication_messages');

  if ($this->form_validation->run() == FALSE) //field validation failed
  {
   $data['message'] = lang('auth_login_validation_error');
   $this->load->view('authentication/login_form',$data);
  }
  else //fields ok
  {
   $username = $this->input->post('username',TRUE);
   $password = $this->input->post('password',TRUE);
  
   //load model, it is inside a subfolder, models/authentication/authentication.php
   //THE EXECUTION STOPS AT THIS LINE IF I REMOVE IT THE CONTROLLER GOES ON
   $this->load->model('authentication/Authentication');

   //$this->Authentication->init($username,$password); //inizializza l'oggetto
  
   $result = FALSE; // was $this->Autentication->login(); changed to debug
   if ( ! $result) //login failed
   {
    $data = array(); //reset dell'array $data
    $data['message'] = lang('auth_login_error');
    $this->load->view('authentication/login_form',$data);
   }
   else //login successful
   {
    $this->load->view('authentication/login_success');
   }
  }
}
}

Model
[code]
class Authentication extends CI_Model
{
function __construct()
{
parent::__construct();
}
}

El Forum

[eluser]InsiteFX[/eluser]
Because you have the first character upper case should be this
Code:
$this->load->model('authentication/authentication');

El Forum

[eluser]Alhazred[/eluser]
I've tried but that didn't help.
I've solved in this way

Renamed the model file from authentication.php to authentication_model.php
Model's code
Code:
class Authentication_model extends CI_Model
{
function __construct()
{
  parent::__construct();
}

...
}

Controller's code
Code:
$this->load->model('authentication/Authentication_model');
$this->Authentication_model->init($username,$password);
...

In other words I have added _model to the model class name and filename.
Is it required to use _model?
From the user guide seems it is not, but without the code doesn't work.

El Forum

[eluser]Aken[/eluser]
The class name has to match the file name. If your model class is named "Authentication", your file name should be "authentication.php". If you name it "Authentication_model", authentication_model.php, etc...

Also make sure you do not have any controllers and models with the same class name, or you'll receive an error.

El Forum

[eluser]Alhazred[/eluser]
[quote author="Aken" date="1341777974"]...
Also make sure you do not have any controllers and models with the same class name, or you'll receive an error.[/quote]
This is the problem then, the controller class is named Authentication too.
Thank you.