Redundancy on HTML |
[eluser]Unknown[/eluser]
Dear members of this community, Since i`m new to CI, i`m not sure whether im approaching my project right. But before i start, i would like to point out that i enjoy working with CI! Anyway, i have a question regarding semi static HTML output. For instance is it possible to have a static HTML document which loads automatically? Because, obviously have some static html pages which have to be loaded every time. And since i have to run $this->load->view(); on every function, i wondered if there is a way to 'bypass' this. My doctype, my meta and css styles dont have to called everytime right? I was wondering if there could be some sort of MAIN controller which could load everytime and within this main controller, you can give some parameters regarding the page you need. This would reduce code and im pretty sure it`s a feature somewhere within CI, or otherwise a certain approach to it, but i can`t figure it out. So if any of you could help me understand how it works, i would really appreciate it! With kind regards, James Lewis
[eluser]kyleect[/eluser]
http://www.google.com/search?client=safa...8&oe=UTF-8 Create "MY_Controller" and put the code in there. Now, here is the way I did it because I needed a way to dynamically load css and JS. All you have to do is set $this->views['content'] with name of the view you want to load. This should give you the basic jist and a jumping off point. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[eluser]jedd[/eluser]
Extending the core controller using MY_Controller is my preferred approach, too. I have waxed lyrical on the subject [url="http://codeigniter.com/wiki/Header_and_Footer_and_Menu_on_every_page_-_jedd/"]in the wiki[/url]. Unsurprisingly this question pops up every few minutes, and there's a few other ways you can approach this problem.
[eluser]JoostV[/eluser]
You can also create a main layout template containing all the standard stuff. Then you let this main template load a specific subtemplate that you specify in the controller. I like this approach because it doesn't clutter my controllers with view-related stuff. Controller: Code: function user () Main view: Code: <?php header('Content-type: text/html; charset=utf-8'); ?>
[eluser]überfuzz[/eluser]
I say My_controller. Mine fetches system data, example; css, meta, pathways to script, etc using methods that merely points out the config file. By the way right after I did the first setup I saw that theres heaps of helpers doing this kind of stuff. >:-( So then the model got toned down, or should I say tuned in the right key... Just saying, so you don't make the same mistake. ;-) I alter standard viewers with custom. So a bunch of controllers might be loading plain_text.php and others like controller news loads view news. But all the view-files are loading html_head, html_foot, maybe menu.php etc.
[eluser]JoostV[/eluser]
Well, I can certainly see an advantage to having specific viewdata handy in your controller. You could for instance promt loading controller-specific stylesheets or javascript files/scripts from you controller. Similar to the headLink(), headScript(), etc functionalities in Zend_View. Code: $this->view['assets']['meta']['keywords'] .= 'some,extra,keywords'; |
Welcome Guest, Not a member yet? Register Sign In |