CodeIgniter Laravel PHP Example Javascript jQuery MORE Videos New

Pass parameter from controller to view file - CodeIgniter framework


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:

  • parameter.php (CodeIgniter\application\controllers\parameter.php)
  • parameter_view.php (CodeIgniter\application\views\parameter_view.php)

parameter.php

<?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); 
		}  
}  
?>

parameter_view.php

<!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

Output

Welcome to Students Tutorial .