R
R
r_ramil2020-08-23 12:25:02
CodeIgniter
r_ramil, 2020-08-23 12:25:02

Undefined variable: Why can't pass variable from controller?

Good day everyone. I am new to php and codeigniter.
I'm trying to pass data from the database to the view,
but when accessing the mac_turleri variable, an undefined variable error occurs.
I have a suspicion that I am doing something wrong in the controller.

To start with, in the Bulten.php view, I try to output at least something:

<?php 
foreach ($mac_turleri as $turler) {
  echo $turler;
}
?>


Here is the Get_turler.php controller itself:
<?php 
  class Get_turler extends CI_Controller {
    function __construct() {
      parent::__construct();
      $this->load->model('Betradar_model');
    }

    public function mac_turleri() {
      $data['mac_turleri'] = $this->Betradar_model->mac_turleri();
      $this->load->view('Bulten', $data);
    }
  }
 ?>


Here is the model Betradar_model.php, here is the call to the database itself:
static function mac_turleri(){
    return self::$db->where(array('betradar_id'=>0))->Select("*")->get('mac_turleri')->result();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2020-08-23
@ThunderCat

firstly, you haven’t checked shit and are trying to assemble a large structure right away, without testing its modules. Learn to debug.

public function mac_turleri() {
      var_dump($this); exit; // проверьте что вообще что-то вызывается отсюда
      $data['mac_turleri'] = $this->Betradar_model->mac_turleri();
      var_dump($data['mac_turleri']); exit; // верхий дамп нужно закоментить конечно. 
                                             //Вангую что из модели ничего не возвращается
      $this->load->view('Bulten', $data);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question