Welcome Guest, Not a member yet? Register   Sign In
data passed to view - using objects rather then arrays

passing data

$data = array(
'title' => 'My Title',
'heading' => 'My Heading',
'message' => 'My Message'

$this->load->view('blogview', $data);

And here's an example using an object:

$data = new Someclass();
$this->load->view('blogview', $data);

can someone post an example of a controller file with Someclass being used to define the title, heading, and message? the example above is provided in documentation, but without context.

You can use a standard object like this:
$data = new stdClass();
$data->title = 'My Title';
$data->heading = 'My Heading';
$data->message = 'My Message';

$this->load->view(‘blogview’, $data);
You can also, of course, use database result objects as well.
$this->db->where('id', $id);
$q = $this->db->get('blog_items');
$data = $q->result():
// or even add more data to the object first
$data->my_other_info = 'other info'
$this->load->view('blogview', $data);

Theme © iAndrew 2016 - Forum software by © MyBB