Variable Error CodeIgniter

0

I'm working on Codeigniter and I have a variable error. I am newly familiar with this framework and well the code is as follows:

Controller:

public function Todo(){

    $new_id = $this->input->post('id');

    $this->load->model('Model_app');
    $data = $this->Model_app->GetNumeroActual($new_id);

    if (!$data == null) {

      $numero_actual_atencion = $data->numero_actual_atencion;

      $this->load->model('Model_app');
      $data = $this->Model_app->GetLetraServicio($new_id);

      $identificador = $data->identificador;


      $this->load->model('Model_app');
      $data = $this->Model_app->GetModuloAtencionID($new_id,$numero_actual_atencion);

      $moduloatencion_id = $data->moduloatencion_id;

      $this->load->model('Model_app');
      $data = $this->Model_app->GetNumeroModulo($moduloatencion_id);

      $identificador2 = $data->identificador;

      header('Content-Type: application/json');
      echo json_encode(array($numero_actual_atencion,$identificador,$moduloatencion_id,$identificador2));


    }

}

The case is that I enter an id and it returns a numero_actual_atencion , I ask if the var $data is different from null and inside the if I take the numero_actual_atencion and save it in a variable, then I send the same id to another query and I save what it returned in the var $identificador , next act I send the same id and the numero_actual_atencion obtained and I keep it in &moduloatencion_id , I send the moduloatencion_id and the return I keep it in the variable $identidicador2 and finally I apply

echo json_encode(array($numero_actual_atencion,$identificador,$moduloatencion_id,$identificador2));

to later be able to consume your data.

The error that throws me is the following:

  

A PHP Error was encountered

     

Severity: Notice

     

Message: Trying to get property of non-object

     

Filename: controllers / HernannMovil.php

     

Line Number: 27

     

Backtrace:

     

File: /Applications/XAMPP/xamppfiles/htdocs/wsatencion/application/controllers/HernannMovil.php   Line: 27   Function: _error_handler

     

File: /Applications/XAMPP/xamppfiles/htdocs/wsatencion/index.php   Line: 315   Function: require_once

Apparently the error is in this line:

$this->load->model('Model_app');
$data = $this->Model_app>GetModuloAtencionID($new_id,$numero_actual_atencion);

I think I'm not sending the var $numero_actual_atencion

causing it not to bring any data back.

    
asked by Hernan Humaña 15.12.2016 в 21:59
source

4 answers

3

It is somewhat complicated to be able to decipher your error with so little code, but I invite you to try to check all the objects that you collect from your Database, that is:

$this->load->model('Model_app');
$data = $this->Model_app->GetNumeroActual($new_id);


////// Aquí compruebas que realmente hayas obtenido 
////// datos de registro de tu anterior consulta (correcto).......
if (!$data == null) {

  $numero_actual_atencion = $data->numero_actual_atencion;

  $this->load->model('Model_app');


  ///// Pero a partir de esta consulta, das por supuesto que 
  ///// recibirás datos (temerario e imprudente) 
  $data = $this->Model_app->GetLetraServicio($new_id);


  ///// Llegado a este punto, $data puede ser NULO y el error es acceder
  ///// a esta variable como si fuese un objeto, lo mismo te ocurre en las
  ///// consultas sucesivas. 
  $identificador = $data->identificador;


  $this->load->model('Model_app');
  $data = $this->Model_app->GetModuloAtencionID($new_id,$numero_actual_atencion);

  $moduloatencion_id = $data->moduloatencion_id;

  $this->load->model('Model_app');
  $data = $this->Model_app->GetNumeroModulo($moduloatencion_id);

  $identificador2 = $data->identificador;

  header('Content-Type: application/json');
  echo json_encode(array($numero_actual_atencion,$identificador,$moduloatencion_id,$identificador2));


}

On the other hand, I do not understand why you load the model for each of the queries within the same method.

In such a case, I would use a if ( ..... !== NULL in each of the queries and if the structure of the tables in your Database allows it, it would reduce it to a single query built with JOINS.

Obviously, all this is very relative considering the little code you show in your question.

    
answered by 11.02.2017 / 12:37
source
1

Seeing the code gives me the feeling that you have left a ';' at the end of this instruction:

$moduloatencion_id = $data->$moduloatencion_id
    
answered by 15.12.2016 в 22:11
1

Good times
Probably your mistake is in that you add another "$" additional:

 $identificador = $data->$identificador;

The correct way to access is:

 $identificador = $data->identificador;
    
answered by 15.12.2016 в 22:11
0

The error is because you can not find the model file, because you can not access Model_app from that line.

Verify that the model has the same physical and internal name of the class.

  

Ex: file Model_app.php declare class class Model_app extend

    
answered by 05.05.2017 в 23:53