

Unlock your Android lock screen pattern with your Google Login (only Android 4.4 and below).Unlock your Android device using Android Device Manager (ADM).Forgot your Android lock screen pattern, PIN or password? Here’s what to do.Javascript is not enabled! Please turn on Javascript to use this site.įrom my controller, I will pass the name of the view to $data. Here is an example: Īssets/css/" rel="stylesheet" type="text/css" />Īssets/css/main.css" rel="stylesheet" type="text/css" /> Then from this template file I call my additional views. This file contains all of my my main site layout. I create a file called template.php in my views folder. If you are always loading the same views on several pages (this is finally the answer to the question), two options depending on your needs:.I frequently extend CI_Controller to overload $this->load->view with extra parameters dedicated to my application to keep my controllers clean.You can add optional parts (for example a third $javascript variable at the end of the body).Look how views are concatenated: method chaining pattern, or should we say: concatanated chaining pattern!.Each view is now dedicated to one and only one stuff.You no longer have HTML markup opened in one view and closed in another.Look how beautiful and clear is the source code.$this->load->view('templates/page', $data) $this->load->view('templates/modal-login', '', TRUE) $this->load->view('home/index', $myData, TRUE) $this->load->view('templates/alert', $myData, TRUE) $data = $this->load->view('templates/navbar', '', TRUE) $this->load->view('templates/javascript', '', TRUE) Here is my controller: $data = $this->load->view('templates/google-analytics', '', TRUE) Of course, I had several views but they are concatenated to build the $header and the $content variables. The best option I finally keeped on all my websites is the following architecture: I tried almost all the answers proposed on this page and many other stuff. Then simply: $this->show("/views/viewname/whatever_V.php")

loads custom class objects if not already loaded $this->load->view('templates/footer', $this->viewdata) $this->load->view($viewloc, $this->viewdata) $this->load->view('templates/header', $this->viewdata) So subclasses can be defined freely, and a single method to show view.Īlso selected constants can be passed to javascript in the header. Or more complex, but makes life easy is to use more constants in boot. When you need to load different js, css or whatever in the header or footer use the _construct function to $this->load->vars $this->load->view('layouts/application', $data) $d = 'fooview'Ĭontroller class Dashboards extends CI_Controller Now when you call the init from the controller all the heavy lifting is done and your views will be wrapped inside and tags, your headers and footers will be loaded in. Now create a view head.php with contents: Īnd create header.php and footer.php views as appropriate. Now create the view html.php with contents: If you take this idea to the extreme, you can make some interesting modular layouts:Ĭonsider if you create a view called init.php that contains the single line: $this->load->view('html') This is actually a very simplistic version of how I personally load all of my views. Then from your controller you can do something like: $d = 'body' The contents of template.php: $this->load->view('templates/header') Create a file called template.php in your views folder.
