Welcome Guest, Not a member yet? Register   Sign In
routing and controllers
#1

[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
#2

[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?
#3

[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.
#4

[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(){}

}
#5

[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()
#6

[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.
#7

[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.
#8

[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




Theme © iAndrew 2016 - Forum software by © MyBB