I don't think you should put your admin functions in their own
controller.

First, having a separate admin controller means that, instead of just
loading one primary model per controller, you'll be stuck handling a
ton of models within that one controller, which could get messy and
almost certainly inefficient.

Also, instead of being able to name your functions "admin_edit",
"admin_index", etc., you'll need unique names for each model -
"admin_users_edit", "admin_pages_edit", etc. Or, you could just have
one massive admin_edit function. Or, your admin_edit function could
just call a bunch of other internal functions. Any way you look at it,
though, it'll be messy (again).

Basically, if you keep a model's admin functions in that model's
controller, you'll always know what you're working with.

Why do you want to separate the functions, anyway? If you're worried
about duplicate code (e.g. ten identical admin_edit functions), you
could move some of your common functions that are the same in every
controller to AppController. I did this for admin_delete and
admin_edit, as well as some other ones I wrote (admin_publish,
admin_unpublish, etc.). My 'stock' admin_delete in AppController, for
example, looks like this:

function admin_delete($id = null) {
                if (!$id) {
                        $this->Session->setFlash(__('Invalid id for ' . 
$this->modelClass,
true));
                        $this->redirect($this->referer());
                }
                if ($this->{$this->modelClass}->del($id)) {
                        $this->Session->setFlash(__($this->modelClass . ' 
deleted', true));
                        $this->redirect($this->referer());
                }
        }

If I need extra functionality for a certian controller I can just
define admin_edit() in that individual controller. But most of the
time, it works just fine.

Anyway, hope this helps you decide.

- Jamie

On Oct 20, 8:28 am, "Dave Maharaj :: WidePixels.com"
<d...@widepixels.com> wrote:
> Can you, or suggest , reasons for or not to....
>
> create an admin_controller and keep all admin functions separate from the
> other controllers?
>
> Dave
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to