How to use several classes on one page? |
[eluser]mr. echo[/eluser]
Hello there! I just installed ci today and after my first glance, tries and tutorials I must say: It's great! Congratulations to the authors!! :-) My question is probably a typical newbie question and is likely already covered somewhere. However I couldn't find a proper answer. So if anybody could provide me with some links... Let's say I want to create a project where I want to create objects of several classes on specific pages, e.g.: - navigation-class, same class implemented on every page - content-class, same class implemented on every page - contact-form-class implemented on page x only - etc. How do I go about doing this since as I understand it on each view-file (which will be my uri & page) I can only implement one controller? Any answer / link would be appreciated! Thanks. Mr echo PS: A hint on how to create a navigation-class I found in this thread: http://ellislab.com/forums/viewthread/98704/ But it has a rather brief answer and no tipps on how to implement,
[eluser]mr. echo[/eluser]
O.K., I guess I found the solution: ;-) If I want sth. to appear on every page of my project, e.g. a header, I would extend the core class Controller ( http://ellislab.com/codeigniter/user-gui...asses.html ) Code: <?php Is this best practice? Any comments / suggestions? Thx
[eluser]jedd[/eluser]
Well, it's a practice. Have a read of this thread - it's what I've adopted for my practice: [url="http://ellislab.com/forums/viewthread/106945/"]http://ellislab.com/forums/viewthread/106945/[/url] I'd suggest that you don't call out to view within the constructor, though. It doesn't seem the most elegant approach, as there'll always be exceptions. It might be better to have a pro forma section that assembles your views and then dumps them out. Again, this is what I've started doing after some advice on here, and it's working reasonably well. But yes, extending the controller is pretty common practice I gather. Here's mine (somewhat snipped) Code: function MY_Controller () { My view code is very basic - perhaps 40 lines - and includes a bunch of div's with echos inside that dump the 4 or 5 major components of the page.
[eluser]mr. echo[/eluser]
Thx for your answer! It seems though that I always have to initialize the component I want to appear on each page. If e.g. I always want a header to appear on every page, I always have to type Code: $this->head(); Or is there a simple way to make a code-snip appear on every page where I want it to appear?
[eluser]jedd[/eluser]
[quote author="mr. echo" date="1236573990"]Thx for your answer! Or is there a simple way to make a code-snip appear on every page where I want it to appear?[/quote] There is. Go and read [url="http://ellislab.com/forums/viewreply/538402/"]this particular bit[/url] from the thread I posted above. So the answer to your question is yes and no. As always No, you don't have to initialise it - that's done in the MY_controller which happens automatically for all your inherited controllers. If you adopt the approach from that thread (above) then your template view becomes all you ever call, and you just modify the contents of the other DIVs. That is to say, your consistent menu code (for example) doesn't require the code-snip on each page. And that's the Yes bit, though it assumes you're happy to go with that 'generic view' approach and make calls out to generate the views for the DIVs within the full page view. Does this make more sense?
[eluser]mr. echo[/eluser]
[quote author="jedd" date="1236574947"]Does this make more sense?[/quote]Uh..well I guess I have to get into this a bit more deeply.... Thanks for trying to help a newbie! :-) I just found this though: Quote:Template is right for you if:Yes, I do! ;-) http://www.williamsconcepts.com/ci/codei...index.html |
Welcome Guest, Not a member yet? Register Sign In |