Home >>Codeigniter Tutorial >Codeigniter Views
The view is a simple webpage(designing page) which called by Controller.
The view may contain Navbar, Header, Footer, Sidebar, slider etc.
The view(designing page) can't access directly it always called by Controller.
Lets create a simple view page and call on a Controller's method. Ex
<!DOCTYPE html> <html> <head> <title>About CI View</title> </head> <body> <h1>About Codeigniter Views</h1> </body> </html>
Save this file inside Application/views/about.php.
The view can be loaded on a controller following syntax :
$this->load->view('view_page_name');
Sometimes we can create different directly like user, admin etc. inside user directory we may store header, footer,sidebar for users same as admin inside admin directory, in this case we can call like :
$this->load->view('directory_name/view_page_name');
Add a new mehtod about() on Hello Controller Application/controllers/Hello.php.
<?php class Hello extends CI_Controller { public function index() { echo "Hello World"; } public function about() { $this->load->view('about'); } } ?>
Here Hello Controller has now 2 methods. One is index() that contains "Hello World" message only. Second method about() is calling about.php view page. Note : inside Controller no need to call page extension of view.
Syntax
http://localhost/index.php/hello/about