Passing Parameters in CodeIgniter
Now we'll see an example to pass parameters from controller to view.
1) Download CodeIgniter and name it. We have named it as params.
2) Create a file para.php in application/controllers folder.
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
class Para extends CI_Controller{
// declaring variables
var $name;
function __construct(){
parent::__construct();
// passing value
$this->name="CodeIgniter";
}
function tut()
{
$data['name']=$this->name;
// define variable sent to views
$this->load->view('para_view',$data);
}
}
?>
3) Create a file para_view.php in application/views folder.
<!DOCTYPE html>
<html>
<head>
<title>Passing Parameter</title>
</head>
<body>
<h3>Hello, This is <?php echo $name ; ?> Tutorial.</h3>
</body>
</html>
4) Run the program on your browser with URL
http://localhost/params/index.php/para/tut
5) Following output will appear on the screen.