CodeIgniter Forums
routing and controllers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: routing and controllers (/showthread.php?tid=1745)



routing and controllers - El Forum - 06-24-2007

[eluser]deineMudder[/eluser]
Hello,
sadly i got another basic question i guess, where i lack understanding of CI.

my actual controller folder looks like this
Code:
controllers
+ admin
  - user.php
  - navigation.php
  - article.php
  - roles.php
  - ....
- homepage.php

im trying to create a small CMS for a site and thought that structure for the administration part could be handy.

each controller (i.e. user.php) has the functions insert, edit, delete ...
as soon as i try to access those controllers hes trying to load a function of admin

controller (admin), function (user)
instead of subfolder (admin), controller (user), function (index)

anyone who could help a newbie to set it up correctly? Wink


routing and controllers - El Forum - 06-24-2007

[eluser]marcoss[/eluser]
Hi there, I'm using the same approach, and is working fine, so probably routing is not working fine.

How are you trying to access the controllers inside the directory?


routing and controllers - El Forum - 06-24-2007

[eluser]deineMudder[/eluser]
[quote author="marcoss" date="1182686701"]Hi there, I'm using the same approach, and is working fine, so probably routing is not working fine.

How are you trying to access the controllers inside the directory?[/quote]

as i said i just tried it with www.mydomain.com/admin/user

to get to the user controller.
i have no routing set up yet.


routing and controllers - El Forum - 06-24-2007

[eluser]marcoss[/eluser]
[quote author="deineMudder" date="1182687356"]
as i said i just tried it with www.mydomain.com/admin/user

to get to the user controller.
i have no routing set up yet.[/quote]

In that case, the user controller (inside admin dir) should have an index() function to handle the default requests.

If you want to trigger an specific function by default, lets say manage users, you can do that this way.

Code:
class User extends Controller {

    function User(){
        parent::Controller();    
    }
    
    function index(){
        $this->manage()
    }
    
    function manage(
        /*
            manage code here
        */
    )
    
    function add(){}
    function edit(){}
    function delete(){}

}



routing and controllers - El Forum - 06-24-2007

[eluser]deineMudder[/eluser]
[quote author="marcoss" date="1182687926"][quote author="deineMudder" date="1182687356"]
as i said i just tried it with www.mydomain.com/admin/user

to get to the user controller.
i have no routing set up yet.[/quote]

In that case, the user controller (inside admin dir) should have an index() function to handle the default requests.

If you want to trigger an specific function by default, lets say manage users, you can do that this way.

Quote:class User extends Controller {

function User(){
parent::Controller();
}

function index(){
$this->manage()
}

function manage(
/*
manage code here
*/
)

function add(){}
function edit(){}
function delete(){}

}
[/quote]

/admin/user leads to a 404 instead to the proper controller
in controllers/admin/user.php -> index()


routing and controllers - El Forum - 06-24-2007

[eluser]marcoss[/eluser]
mmm, is any of your controllers working? You said you have a homepage.php, is site.com/homepage working?

If not, try using this structure, site.com/index.php/admin/user/index.


routing and controllers - El Forum - 06-24-2007

[eluser]deineMudder[/eluser]
yes my controllers are working

found the problem Wink
i had a /controllers/admin.php from early testing.
so CI identified admin/user as function of admin instead of seeing it as its own controller.

ty anyway. the forum is a great help for starters like me.


routing and controllers - El Forum - 06-24-2007

[eluser]marcoss[/eluser]
That is the expected behaviour, I've just used the file tree you provided as a guide and didn't see the admin.php listed so i dismissed it as an option.

Good to know that is solved now Wink