Welcome Guest, Not a member yet? Register   Sign In
building an efficient admin control panel

hello guys,

i am working in those days on an admin control panel, and i want to hear some tips from u, and to see what do u think about it, and how efficient is it.

so... i have two controllores: one is an "admin" controlloer. in there i control on the page and directing the user to the wanted admin pages. +the login validating is also in there.
the second controller is called "Execute". in there i am actually making all the actions. this controller is checking the forms and validating them, and working with the data from them.

those controlloers are in the same directory with all the other controllers.

now the views files.
i have a different directory for the admin view files, and for each page i have a different view file.

i have zero models, helpers or librarys for the admin control panel.

so guys.. what do u think? what is ur suggestions? how can i make it better?

[eluser]Michael Wales[/eluser]
If it works for you - go for it.

Personally, I usually manage my apps in the following way:

1. Establish MY_Controller.php to create a Public_Controller and Admin_Controller class. These are used to determine whether the user needs to be logged in or not, as well as other various functions.

2. Create a controller admin that extends Admin_Controller - this handles very generic administrative functions.

3. Create a controller named admin_pages which houses all of the methods for page administration - this is what I like to call a child-admin method. We would have things like view, create, edit, delete in here.

4. Setup the following routing rules:
$route['admin/([a-z]+)/([a-z]+)/([a-zA-Z0-9_-]+)'] = "admin_$1/$2/$3";
$route['admin/([a-z]+)/([a-z]+)'] = "admin_$1/$2";
$route['admin/([a-z]+)'] = "admin_$1";
So, links to /admin/pages will be routed to the admin_pages class, with trailing segments for methods and a parameter.

5. I create a directory /views/admin/ which houses directories for each of my admin_* classes. For example: /views/admin/pages/create.php would be the path to the view that is loaded by the admin_pages->create() method.

For a past project, we used debug_backtrace in a library called MyAuth to check the function the user was calling, and separate database tables to assign each function name to a role id, then assigned that role per user.

IMO this was a pretty flexible and allowed for addition of new functions, roles, etc.

If you're interested, let me know and I can post some sample code.

walesmd - thx for the tips. i'll try to make something like what u wrote but here are some questions:
1. admin_pages controller is actually executes all the actions?
2. "Create a controller admin that extends Admin_Controller - this handles very generic administrative functions" - generic functions? what do u mean?

thank u.

sandwormusmc - it sounds interesting. can u add some more detailes about the way u work?


[eluser]Sarfaraz Momin[/eluser]
WHat walesmd meant to say is that the Admin_controller would check weather the user is logged in as the siteadmin so he can be redirected to the control panel. In short it takes care of the AUTH of the admin panel. This is very generic admin task to keep the user validated till he has not logged off. Also there can be anything you want to do like keep a track of what the siteadmin has done changes or so. These are what is meant by generic admin task.

Hope that makes sense.

Good Day !!!

thx Sarfaraz Momin, now i get it. so u actually have a hirerchy that looks like that:
admin_control that handels that login -->> admin controller that redirects you to the wanted pages -->> admin controller (admin_pagees) that makes all the actions.

is that right?

- and what about debuging hlpers? what kind of bugs are you checking?
the only bugs that i am checking in a helper, is to see if the query has results for the page, and to see if the page number in the pagination is valid.

[eluser]Michael Wales[/eluser]
class Admin_Controller extends Controller {
  function admin_controller() {
    if (!$logged_in) redirect('');
    $user = getUser($uniqueID);

class Public_Controller extends Controller {
  function public_controller() {

class Admin extends Admin_Controller {
  function __construct() {

  // This is just here for "need-be" circumstances - maybe logout?
  function logout() {

class Admin_pages extends Admin_controller {
  // This was accessed via domain.com/admin/pages
  // routes.php made a pimp-ass assist and let us route that URI to this controller

  function __construct() {

  function create() {
    // Let's make a new page

Note: If you copy-paste that code and complain it doesn't work I swear...

wals - i tried to copy paste it to see if it works, but i keep getting the same error! :bug:

just kidding lol.. ur last setence made me smile.
any way... i think now i understand it more, and if u don't mind i might use it on my next works - i'm sure it will spice 'em up.

but there is one thing i don't get: in the admin_pages.php u call a model:

why do u call this model? besides, i steal didn't get the whole idea of models :down: (and yes, i red the user guide)

[eluser]Michael Wales[/eluser]
I only called that model based on principle, probably because you would be using it in that controller.

The Admin_pages controller is the controller used to, obviously, administer pages. The pages_m model contains all of our methods that interact with the database. By loading this model within the constructor you save yourself some typing later on.

For instance, if we had a create() method, which created a new page:
function create() {
  $rules['title'] = 'trim|required|max_length[255]|callback__check_title';
  $rules['body'] = 'trim|required';
  $rules['tags'] = 'trim';
  $rules['btnSave'] = 'required';
  $fields['title'] = 'Page Title';
  $fields['body'] = 'Page Content';
  $fields['tags'] = 'Tags';

  if ($this->validation->run()) {
    if ($this->pages_m->createPage($_POST)) {
      // Go view the page
    } else {
      show_error('An unexpected error occurred, please try again.');
  } else {

In pages_m->createPage I would futher validate my data, ensuring I am only inserting columns I am expecting from this particular form, and then make the database insert.

I guess I strayed from the point - the reason it's there is because you're probably going to use it in every method within this controller. Big Grin

Theme © iAndrew 2016 - Forum software by © MyBB