In this example we are going to show you how to Pass parameter from controller to view file in CodeIgniter framework PHP.
Here we using 2 files for pass parameter from controller to view:
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
class Parameter extends CI_Controller{
/* declaring variables */
var $name;
function __construct(){
parent::__construct();
/* passing value */
$this->name="Students Tutorial";
}
function tutorial()
{
$data['name']=$this->name;
/* define variable sent to views */
$this->load->view('parameter_view',$data);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Passing Parameter</title>
</head>
<body>
<h3>Welcome to <?php echo $name ;?> .</h3>
</body>
</html>
Now run the program on your browser with the below URL:
http://localhost/codeIgniter/index.php/Parameter/tutorial