Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to make Admin pages in CodeIgniter?

I'm working on an app in CodeIgniter, and I want to have admin pages for several of the objects in the application, and I'm wondering what would be the better way to put these into an MVC structure.

Idea 1: In each controller, have an admin function, and add all of the admin pages I would like into that function. example URL: domain.com/articles/admin

Idea 2 Make a new admin controller, which would have to reference many different models, and put all of the admin pages in there. example URL: domain.com/admin/articles

Which way would be better?

Edit for clarification: By admin functionality, I mean being able to do the basic CRUD actions on any object, and be able to display a list of all of said object.

like image 765
GSto Avatar asked Nov 09 '09 20:11

GSto


1 Answers

Definitely a different controller at least!

I used to think that I could keep all my admin functions in a single controller, but as my programs grew, I realized that I needed multiple controllers in my administration section.

So, I created a folder inside my controllers folder with the name "admin" and put all my administrative controllers in there. So my folders would look something like:

  • application
    • controllers
      • front.php
      • welcome.php
      • admin
        • dashboard.php
        • useradmin.php
  • etc...

One problem this creates, however, is when you type http://mysite.com/admin in your browser, it returns a 404 page. So, go to your "application/config/routes.php" file and add a custom route:

$routes['admin'] = 'admin/dashboard/index';
like image 111
caseyamcl Avatar answered Oct 13 '22 04:10

caseyamcl