CodeIgniter Passing Parameters

In this section, we'll see an example to pass parameters from controller to view.

The Controller

Using a text editor, create a controller called Parameter.php. In it, place this code and save it to your application/controllers/ directory:

<?php
   class Parameter extends CI_Controller {
    
      public function __construct() { 
         parent::__construct(); 
      }
        
      public function index() {
	 $data['title'] = "Welcome to Nexladder! This is CodeIgniter Tutorial (Passing Parameter)"; 
         $this->load->view('parameter_view', $data); 
      }
   } 
?>

Creating the View

Using a text editor, create a view file called parameter_view.php. In it, place this code and save it to your application/views/ directory:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>CodeIgniter Passing Parameter</title>
</head>
<body>
     <div class="container">
	   <h4><?php echo $title ; ?></h4> 
     </div>
  </body>
</html>

To try your view, visit your site using a URL similar to this one:

http://localhost/codeigniter/index.php/parameter/index

Codeigniter Passing Parameter