Thursday, June 23, 2016

Codeigniter tutorial 3

   No comments     
categories: 
I introduced CodeIgniter routing and parameter passing on the controller in previous posts.

Now I show creating functions to load 'view' files where we have our UI.
Create a file in 'code\application\views'. Here the 'code' is the renamed folder of extracted CodeIgniter zipped file. 

first_view.php

<html>
<head>
<title>View</title>
</head>
<body>
<h1>This is a view file</h1>
<h2>The UI part</h2>
</body>
</html>

in the code\application\controllers edit the hello.php.

<?php
class Hello extends CI_Controller{
public function index(){
$this->first();
}
public function first(){
$this->load->view('first_view');
}

}
?>

This function will load the view file.

Then the URL to get the view file from the controller method is;
localhost/code/index.php/hello



Here, since I used special function my URL does not contain any controller function name.

Now I create another file in view say `header_view.php`

<html>
<head>
<title>View</title>
</head>
<body>
<h2>Header</h2>
 <hr/>
</body>
</html>


And I load both the functions by the following file `hello.php`

<?php
class Hello extends CI_Controller{
public function index(){
$this->first();
}
public function first(){
$this->load->view('header_view');
$this->load->view('first_view');
}
}
?>


Here both the view files loaded as one output.

0 comments:

Post a Comment