Answer the question
In order to leave comments, you need to log in
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;
}
?>
<?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);
}
}
?>
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
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 questionAsk a Question
731 491 924 answers to any question