Pages, subpages, subsubpages ... best way to achieve? |
[eluser]Unknown[/eluser]
Hello all! :-) I'm not very proficient in CI and I'm in the midst of creating a website with it to learn more about it. Now I got stuck on this issue: subpages (eg. http://example.com/a_page/another_page/). I combed through the forums and it seems routing is the best way. The site I'm creating won't be that big so at the moment I'm using just one controller and the standard CI-way of mapping the first URI segment to the controller method. Stripped down my controller looks like this: Code: <?php As you can see I'm using an _assemble method which does some otherwise redundant stuff like adding a header etc. It also "injects" the optional content and loads the appropriate view. For me it works very well though I don't know if it's a good approach. Anyway, how do you go around creating subpages? Is routing the way to go? It seems to me that adding a lot of entries to routing.php for a lot of subpages seems to be rather cumbersome. Or should I just take the second URI segment(the method's parameter) and switch through it? Is there any regular/standard way to get something like this done in just one controller? Thanks for any input! Regards
[eluser]Pascal Kriete[/eluser]
Hey Therapiekind, First off it looks like you're having some trouble with that controller, so let's refactor. The view handling is much smarter than you're making it out to be, just make a template: View - template.php Code: $this->load->view('header'); Any data you pass to this view will be available in all subviews, so we've simplified things a lot. Here's the new controller: Controller - kmx.php Code: <?php And just to get the point across, let's say this is our agb view: View - agb.php Code: <div id="all_data_is_sold"> I'm having a hard time with that subpage stuff. You can get any url segment with $this->input->segment(n), and any stray segment will be passed to your controller as an argument. example.come/blog/show/4 blog controller: view function Code: function show($id) Welcome to CodeIgniter.
[eluser]Unknown[/eluser]
Thanks for the answer, inparo! I didn't even think about loading a view from within a view. And your template.php approach renders _assemble obsolete and cleans up my controller. That's great, too (though it sounded cool to have a function like this ... :roll ![]() Regarding subpages: I think I will parse method parameters and load subpages accordingly. However I'm still curious how others accomplish that. |
Welcome Guest, Not a member yet? Register Sign In |