Header controller? |
[eluser]Felipe Deitos[/eluser]
I got a really newbie question related to templating... here we go: I got a library called Template here is the code... (actually i find this code in some tutorial and i am using it, if anyone got a better one share it please =D) Code: class Template { In my views folder i got a folde called templates with all my templates... I will post my templates/site.php code here so you guys can understand what i am talking about... Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> As you notice, i got a folder called includes inside views and got a header.php inside this folder... My question is, how can i pull some database data in the header.php? Maybe its a little bit confusing but i hope you guys can understand my question Cheers! Thanks for helping
[eluser]ojcarga[/eluser]
Why don't you just call the Code: $this->load->view("path_to_the_header_dot_php/header", $data); And, inside $data you can put all your database data you want to send to the views. Cheers!
[eluser]Felipe Deitos[/eluser]
I know but remember that i am calling $this->load->view('bla') in the view... not in the controller... I am really confused about that... I will try give and example... The Template library that i posted above is already autoloaded and working... This is my home controller... (look at the comments) Code: <?php Here is the templates/home Code: // As you can see this is the template... it calls the header and footer and the var $contents is where the The includes/header is loaded in every page, what i need is to pull some $data here, but i dont see how... Since i load the includes/header in a view and not the controller... Its confusing but i hope someone can try to help me, Thanks for reading. Cheers!
[eluser]adamck[/eluser]
You need to load the views in the controller, loading views from views will make life a pain! have you looked into the template parser? its very easy to use. This is a basic example. Code: function index() then in your views Code: <body> it works very well and saves all the loops etc... having to be written. I have also noticed when you load views in a controller, or a view, it tends to load them in order of what loads first gets displayed first... which means your body will load, then your header, then your footer... the parser fixes this issue! Ad,
[eluser]Felipe Deitos[/eluser]
hummm, i will have to do: Code: $header_data['headstuff'] = $this->home_model->header_stuff(); In every controller? In Every model i will have to do the same query to the header.php?
[eluser]ojcarga[/eluser]
[quote author="Felipe Deitos" date="1353412094"]I know but remember that i am calling $this->load->view('bla') in the view... not in the controller... I am really confused about that... I will try give and example... The Template library that i posted above is already autoloaded and working... This is my home controller... (look at the comments) Code: <?php [/quote] That is your code, cool, now look at this: Code: function index() { So, yes, inside your "includes/header" and "includes/footer" views you can use Code: $data_for_the_header && $data_for_the_footer
[eluser]satej[/eluser]
You can look into this template library. There is also documentation for it. http://williamsconcepts.com/ci/codeignit.../template/
[eluser]Felipe Deitos[/eluser]
#ojcarga first of all thanks for the help you are giving me.. but unfotunately this isnt what i am looking for, i know how to pass and array throw a view and all this stuffs. I will try one more time to explain what i want but not looking to my code this... lets start from zero hehe Im my new site i will have a dropdown menu, in this menu we have the item called products on rollover the products all the categories(comming from database) will dropdown. Thats it, this is my template that will show in everypage of my site... only the menu and the content will come right bellow the menu... (no footer) This is my home controller... Code: // Go into products_model and get categories This is my product controller Code: // Go into products_model and get categories Here is my giant question... i will have to put the $data['menu_categories'] in every controller? There is no way of doing like a header controller? This header controller build the entire header that is loaded just once at the top of every page... This is really hard to explain but it seems so simple and i cannot do this... There is like 1 million posts about templates and no one seems to do something like that. Sorry for bothering you guys! Cheers!
[eluser]CroNiX[/eluser]
[quote author="Felipe Deitos" date="1353434468"] i will have to put the $data['menu_categories'] in every controller? There is no way of doing like a header controller? This header controller build the entire header that is loaded just once at the top of every page... [/quote] No, you can put it in your template library. In the library I use, all I do is pass the template library the CURRENT view from whatever controller. The library automatically puts the header (retrieving data from the database, checking user permissions, only displaying things that that user level allows, etc), menu and footer. It just inserts whatever content I send it in between them. So none of my controllers have anything to do with the header, menu or footer. They just deal with the specific task they are supposed to do. For instance, in my controller... Code: //...do work... //in /application/libraries/Template.php... Code: function generate($page_title, $content) |
Welcome Guest, Not a member yet? Register Sign In |