Welcome Guest, Not a member yet? Register   Sign In
Getting $data into view?
#1

[eluser]deslacker[/eluser]
I'm new to CI and OOP in PHP so please excuse the simple question.

I have a model...and I have a controller...but what I can't figure out is how to display the extracted $data in my view.

I am autoloading the database: $autoload['libraries'] = array('database');

Code:
?php
class Mdl_vehicle extends Model {

    function Mdl_vehicle()
    {
     parent::Model();
    }
    
    function get_all_records()
    {
        $query = $this->db->get('vehicles');
        return $query->result_array();
    }
}
?


Code:
?php

class Ctl_vehicle extends Controller {

function Ctl_vehicle()
    {
        parent::Controller();
        $this->load->model('mdl_vehicle');
    }

    function index()
    {
        $data = $this->mdl_vehicle->get_all_records();
        $this->load->view('view_vehicle',$data);
        $this->output->enable_profiler(TRUE);
    }
}
?
#2

[eluser]gunter[/eluser]
Code:
$data["vehicles"]=$this->mdl_vehicle->get_all_records();
        $this->load->view('view_vehicle',$data);

now you can use the $vehicles array in your view...
Code:
print_r($vehicles);
#3

[eluser]deslacker[/eluser]
Thanks! Works great! I think I'm beginning to get it.
#4

[eluser]lookatthosemoose[/eluser]
and it only gets better the more you learn. CI is bea-u-tiful!




Theme © iAndrew 2016 - Forum software by © MyBB