Basic usage
Unzip Codeigniter 2.20 into a folder called ‘Codeigniter’
1. You need a controller (application/controller/pages.php)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php class Pages extends CI_Controller { public function view($page = 'home') { if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php')) { // Whoops, we don't have a page for that! show_404(); } $data['title'] = ucfirst($page); // Capitalize the first letter $this->load->view('templates/header', $data); $this->load->view('pages/'.$page, $data); $this->load->view('templates/footer', $data); } } |
2. You need a view method (application/views/pages/home.php)
1 2 3 |
Hello World |
3. and maybe a header (application/views/templatesfooter.php)
1 2 3 4 5 6 7 8 |
<html> <head> <title><?php echo $title ?> - Codehavens CodeIgniter Basics</title> </head> <body> <h1>CodeIgniter Basics</h1> |
4. and footer (application/views/templates/footer.php)
1 2 3 4 5 |
<strong>© 2014</strong> </body> </html> |
5. Run the url in your browser
http://localhost/Codeigniter/index.php/pages/view/home
(without a .php extension)
You should then be able to see an output that has a title(name of page), header and content of home.php, with a footer.