Quantcast

Admin Controller

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Admin Controller

Dave Maharaj :: WidePixels.com
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 [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Admin Controller

Jamie Nay

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"
<[hidden email]> 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 [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Admin Controller

Jon Bennett
In reply to this post by Dave Maharaj :: WidePixels.com

Hi Dave,

> create an admin_controller and keep all admin functions separate from the
> other controllers?

Personally I wouldn't. Have a look at the Cookbook source, this is
what I follow - all admin methods except special cases go in
app_controller, streamlines things a lot.

Cheers,

Jon

--
jon bennett - www.jben.net - blog.jben.net

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Admin Controller

Dave Maharaj :: WidePixels.com
In reply to this post by Jamie Nay

Yeah the added model strain I figured as much.

Low down on my problem. User has 5 HABTM relations. Normally you edit all
the user info in 1 call admin_edit in user controller. But I have broken the
info into sections for each HABTM, I managed to write 1 function that will
updated each HABTM so that made the code cleaner, but the User has for 1
specific example has User.email, if they edit the email is suspends the
account until they confirm thier email again. So I need a separate form for
just that function so I now need 2 additional admin functions, 1 to call the
form, and 1 to save it. Same with the Users->Profile contact info. Profile
is made up of lots of fields but I want a user to edit say just the contact
info fields I need a admin_edit_contact and admin_index_contact and all
these exra functions are making agiant mess. Just tossing ideas around to
cleanit up and more readable / manageable

Thoughts on how to combat this?

-----Original Message-----
From: Jamie [mailto:[hidden email]]
Sent: October-20-09 1:39 PM
To: CakePHP
Subject: Re: Admin Controller


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"
<[hidden email]> 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 [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Admin Controller

adam-8

I always thought the same thing as Dave, but finally gave up because
there is no other sensible solution.  I never thought to put common
methods in app_controller!!  I'm so glad I opened this thread, because
this just made cake so much more elegant for me.

On Oct 20, 11:55 am, "Dave Maharaj :: WidePixels.com"
<[hidden email]> wrote:

> Yeah the added model strain I figured as much.
>
> Low down on my problem. User has 5 HABTM relations. Normally you edit all
> the user info in 1 call admin_edit in user controller. But I have broken the
> info into sections for each HABTM, I managed to write 1 function that will
> updated each HABTM so that made the code cleaner, but the User has for 1
> specific example has User.email, if they edit the email is suspends the
> account until they confirm thier email again. So I need a separate form for
> just that function so I now need 2 additional admin functions, 1 to call the
> form, and 1 to save it. Same with the Users->Profile contact info. Profile
> is made up of lots of fields but I want a user to edit say just the contact
> info fields I need a admin_edit_contact and admin_index_contact and all
> these exra functions are making agiant mess. Just tossing ideas around to
> cleanit up and more readable / manageable
>
> Thoughts on how to combat this?
>
> -----Original Message-----
> From: Jamie [mailto:[hidden email]]
> Sent: October-20-09 1:39 PM
> To: CakePHP
> Subject: Re: Admin Controller
>
> 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"
> <[hidden email]> 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 [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Loading...