0
votes

Hey im using codeigniter and i got this error

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: slide

Filename: daxili/slider.php

Line Number: 3

Backtrace:

File: D:\OpenServer\domains\vtgroup\application\views\daxili\slider.php

Line: 3 Function: _error_handler

controller:

public function index() {
    $data['slide'] = $this->slide->get_slide();
    $this->load->view('daxili/slider', $data);
}

view:

<?php foreach($slide as $key => $val) : ?>                  
    <div class="sl-slide" data-orientation="horizontal" data-slice1-rotation="10" data-slice2-rotation="-15" data-slice1-scale="1.5" data-slice2-scale="1.5">
        <div class="sl-slide-inner">
            <img class="bg-img wow fadeInUp" src="<?php echo site_url(); ?>assets/img/slides/<?php echo $val['slide_image']; ?>">
        </div>
    </div>
<?php endforeach; ?>

model:

public function get_slide(){
    $query = $this->db->get('slide');
    return $query->result_array();
}
1
what's the output of your get_slide method ? - hassan
controller: public function index() { $data['slide'] = $this->slide->get_slide(); $this->load->view('daxili/slider', $data); } - Subhan
the output array i mean, check if it a valid array - hassan
Array ( [slide] => Array ( [0] => Array ( [id] => 1 [title] => birinci [slide_image] => 1.jpg ) [1] => Array ( [id] => 2 [title] => ikinci [slide_image] => 2.jpg ) ) ) - Subhan
class Slide extends CI_Controller { public function index() { $data['slide'] = $this->slide->get_slide(); print_r(($data)); } - Subhan

1 Answers

0
votes

Could you post the entire Model and Controller classes? It definitely looks like your get_slide() call is returning something undefined - perhaps a DB connection isn't being made or the model isn't being loaded in your controller.

You could also check $this->db->error(); in your Model class just in case.

Update 2: You are autoloading your model as slide. Is it possible that CodeIgniter will not extract the $data['slide'] into a global variable because it collides with an auto-loaded identifier?

Try renaming it $data['slideArray'] in the controller and doing foreach($slideArray as $key => $val) in the view?