In this article We are going to discuss about How to create and passing the parameters between controller and views in CodeIgniter (CI). In my previous article, I have explained about How to Create a Hello World application in CodeIgniter (CI).
In my previous article, I have clearly explained How to create controllers and views. So, In this article just explain about how to passing the argument (parameters) between controllers and views in CodeIgniter (CI).
Step 1 :
Open the already created "helloworld.php" file in the folder "<root folder>/application/controllers". Add the some codes in that file. The final "helloworld.php" file contains the below codes.
<?php
class Helloworld extends CI_Controller
{
var $text_to_display;
var $text_color;
public function __construct()
{
parent::__construct();
$this->text_to_display = 'World!';
$this->text_color = 'red';
}
public function display()
{
$data['text_to_display'] = $this->text_to_display;
$data['text_color'] = $this->text_color;
$this->load->view('display_view',$data);
}
}
?>
Step 2:
Open the view file "display_view.php" file in the folder "<root folder>/application/views" and add some codes in that file. The final "display_view.php" file contains the below codes.
Hello <font color="<?php echo $text_color; ?>"><?php echo $text_to_display; ?></font>
Step 3:
Paste the below URL in the browser address bar and see the output.
http://localhost/CodeIgniter/index.php/Helloworld/display
In my previous article, I have clearly explained How to create controllers and views. So, In this article just explain about how to passing the argument (parameters) between controllers and views in CodeIgniter (CI).
Step 1 :
Open the already created "helloworld.php" file in the folder "<root folder>/application/controllers". Add the some codes in that file. The final "helloworld.php" file contains the below codes.
<?php
class Helloworld extends CI_Controller
{
var $text_to_display;
var $text_color;
public function __construct()
{
parent::__construct();
$this->text_to_display = 'World!';
$this->text_color = 'red';
}
public function display()
{
$data['text_to_display'] = $this->text_to_display;
$data['text_color'] = $this->text_color;
$this->load->view('display_view',$data);
}
}
?>
Step 2:
Open the view file "display_view.php" file in the folder "<root folder>/application/views" and add some codes in that file. The final "display_view.php" file contains the below codes.
Hello <font color="<?php echo $text_color; ?>"><?php echo $text_to_display; ?></font>
Step 3:
Paste the below URL in the browser address bar and see the output.
http://localhost/CodeIgniter/index.php/Helloworld/display
0 comments:
Post a Comment