CodeIgniter Forums
noob question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: noob question (/thread-1802.html)



noob question - El Forum - 06-27-2007

[eluser]jstrebel[/eluser]
Hey there.. noob here.

I am trying to build a 3 level deep url loading a view at each stage.


My controllor for a user dashboard: dash.php
Code:
function index() {
                $data = array(
                        'morecontent' => '',
                );

                $content = $this->load->view('dash/index',$data,true);
                $this->wrapOutput($content,"Dashboard","dash");
        }
This gives me http://somesite.com/dash

So there is sub section of the dashboard called the account settings

Code:
function settings() {
                
                $data = array(
                        'morecontent' => $this->load->view('dash/settings',array(),true),
                        
                      
                );

                $content = $this->load->view('dash/index',$data,true);
                $this->wrapOutput($content,"Dashboard > Settings","dash");
        }
So above I am loading the settings view into the dash view... and it gives me http://somesite.com/dash/settings

So I want to now load a payment view into settings.. and have the final url be http://somesite.com/dash/settings/payment

My instinct is to create a function called payment() inside of the settings() function.. sort of like nesting folders in a file strcture... but that is not how CI works.

I need to have 3 or 4 subpages inside of settings, that is inside of dash... How best to accomplish this?

Sorry if it does not make sense.. I am thinking like a file system.. if I want to group pages into categories I just nest the file structure... how does one nest functions in a controllor to created nested url's?

It is important for us to use this 3 level structure as /dash will have many 2nd level pages which in turn have more 3rd level pages. like /dash/profile/bio and /dash/profile/privacy etc.


noob question - El Forum - 06-27-2007

[eluser]jstrebel[/eluser]
Sorry.. after a few more searches I found it.. http://www.ellislab.com/codeigniter/user-guide/general/controllers.html#subfolders Smile


noob question - El Forum - 06-28-2007

[eluser]esra[/eluser]
Another approach is to use the Modular Separation extensions on the Wiki. Also do a search for modular separation on the forums. This allows you to create a application/modules/ directory structured like so:

application/
application/modules/
application/modules/dash/
application/modules/dash/controllers/
application/modules/dash/models/
application/modules/dash/views/
application/modules/settings/
application/modules/settings/controllers/
application/modules/settings/models/
application/modules/settings/views/

You can add any number of modules. Dash could be a base controller (do a search for base controller) and all other controllers could be extended from the base controller, allowing base controller code to be shared by your module controllers. You dashboard could use a master view or template and the modules could be loaded into the master view/template.

You might also want to read more about creating routes in the user guide and do a search on the forum for additional examples, especially examples using regular expressions (regex).