Welcome Guest, Not a member yet? Register   Sign In
How to structure the admin zone
#1

[eluser]Dagobert Renouf[/eluser]
Hello guys,

As I was playing a bit with my very first Codeigniter app, I ran into a logical problem, how do I structure the admin zone ?

I searched a bit and found out you guys insert directly into the page controller an admin function, and I don't see the logic in there.

I'm thinking about the url like this : website/index.php/admin/ nothing more.
So I have to create some admin folder with a controller for each part of the site I want to be able to admin, am I right ?

How do I manage to create an admin zone clearly separated from the rest of the site as I explained ? And if you think I'm not seeing things as I should, why ?
#2

[eluser]wiredesignz[/eluser]
Generally the application/controllers/admin/ directory is used to seperate functionality, However there are other ways to achieve more seperation.

You can create a totally seperate application directory structure for administration only and use .htaccess to rewrite /admin/(.*) calls into it.

Or you can create application/modules/ to seperate content, both Matchbox and Modular Extensions were created for that purpose.
#3

[eluser]Jamie Rumbelow[/eluser]
Well, if we take for example, a simple blog application.

In your admin panel, you want three "pages". A new post page, an edit post page, and a delete post page. You could have one singular admin controller, and structure it like this:

Code:
controllers -
    
    admin.php -
        function add_post,
        function edit_post,
        function delete_post

    other.php

    etc. etc....

Or, you could have a system like this:

Code:
controllers -

    other.php

    admin/ -

        add_post.php
        edit_post.php
        delete_post.php

etc. etc..

So it's really up to whatever development flow you are used to.
#4

[eluser]Dagobert Renouf[/eluser]
thank you guys, I see things more clearly now, my main problem is that I still don't have the MVC MIND yet ahah.

I think I'll go with Jemgames second proposition, that's what seems the most simple for me.

thanks.
#5

[eluser]nmweb[/eluser]
I'd bundle the Post actions in one controller though
Code:
controllers -

    other.php

    admin/ -
      post.php
        function add_post,
        function edit_post,
        function delete_post
Also, I'd create an Admin Controller and have your controllers in the admin section extend from that. This way you only have to write authentication in one place etc.
#6

[eluser]Dagobert Renouf[/eluser]
thank you a lot nmweb, that's a great improvement to the last technique.

However, I'm not really sure I'm getting your point about the "admin section extend from an admin controller", could you (or someone who understood) go deeper with that ?
#7

[eluser]Pascal Kriete[/eluser]
Create a new library file called MY_Controller:
Code:
class Administrator extends Controller
{    
    function Administrator()
    {
        parent::Controller();

        // Protect the admin area, etc
        $this->access->restrict('Administrators');
    }

}

Then for your admin controllers you extend the Administrator class instead of the Controller. That way you have common administrative logic in one place.




Theme © iAndrew 2016 - Forum software by © MyBB