Codeigniter: Passing data from controller to view Codeigniter: Passing data from controller to view codeigniter codeigniter

Codeigniter: Passing data from controller to view


$data should be an array or an object: http://codeigniter.com/user_guide/general/views.html

$data = array(    'title' => 'My Title',    'heading' => 'My Heading',    'message' => 'My Message');$this->load->view('results_view', $data);

results_view.php

<html><?php //Access them like soecho $title.$heading.$message; ?></html>


In simple terms,

$data['a'] in controller becomes $a in your view. ($data won't exist in your view, only the index will become available)

e.g.

Controller:    $data['hello']='hellow world';view:echo $hello;


You just need to create a array, you using codeigniter right?

Example on controller:

$data['hello'] = "Hello, world";$this->load->view('results_view', $data);

In de page "results_view" you just have to:

<?php echo $hello;?>

Obs: You can create n datas, just pay attention in the name and make it a array.

ObsĀ²: To use the data use the key of the array with a echo.