loading menu for all controllers ? |
[eluser]hardik[/eluser]
hi, i am bit new to codeigniter. and i have set template like below.. i m creating one template.php Code: <html> now i m loading it using controller like .... Code: class Welcome extends Controller { all code works perfectly but after creating few more controllers like user,categories,....etc i have question how can i load navigation data directly in my navigation view without loading it every time from all the controllers...? is there a way i can load some data directly as my navigation will be in every page in the site? i did search a lot and found great things in wiki. i came to this article http://codeigniter.com/wiki/Header_and_F...ge_-_jedd/ i read it thrice but i didn't get how it works? can anyone help me how i can achieve this ?
[eluser]hardik[/eluser]
i was finally able to solve this at my own thanks to really cool tutorials and help available at CI forums and faq... what i have created is one base controller which will be inherited by all other controllers and that base controller will inherit ci controller class. problem i got was i was not able to understand where to put my files for base controller as well as how i can access those variables that i declare in my base class controller to directly getting in view. so here is what i have written Code: this will be stored in system/applications/libraries/MY_Controller.php , i got headache for this as i put it into controller directory but after searching forums finally i found i need to store it in libraries folder.... now all my default controllers will be inheriting this controller... Code: <?php and finally my template Code: <html> all ci guru's please review my code and tell me is it the right way ? am i doing something wrong or this is ok ?
[eluser]jedd[/eluser]
[quote author="hardik" date="1259336458"] i was finally able to solve this at my own [/quote] Glad to hear. Next time you have a problem, try consulting the [url="/wiki/FAQ"]FAQ[/url] or even [url="/wiki/Header_and_Footer_and_Menu_on_every_page_-_jedd/"]other bits[/url] of the wiki.
[eluser]überfuzz[/eluser]
Nice going harddik. If you're using the same template throughout the site, you might as well put the <head> stuff, the footer and what have you in the template. CI helps you with some nice functions in the url class. Code: <?php echo doctype('xhtml1-strict'); ?>
[eluser]überfuzz[/eluser]
Nice going harddik. If you're using the same template throughout the site, you might as well put the <head> stuff, the footer and what have you in the template. CI helps you with some nice functions in the url class. Code: <?php echo doctype('xhtml1-strict'); ?>
[eluser]Aken[/eluser]
Given that system of doing things also, if your header and footer and whatnot will not change very often, you might as well include their HTML in your template view also. That way you're making only loading two views - the template and the content - instead of four or five views.
[eluser]jwindhorst[/eluser]
Here's the way I handle the header/footer issue. I first create a custom_functions_helper.php file in the helpers directory. Inside there I create this function: Code: function load_view_with_templates($views, $header_data=array()) Then in my controllers, instead of calling the normal Code: $this->load->view('view_name); I call: Code: load_view_with_templates($views, $data); The views parameter can be an array, so if you needed to load multiple views between your header and footer that would also work fine. Hope it helps. |
Welcome Guest, Not a member yet? Register Sign In |