Re: Admin Controller

2009-10-20 Thread Jamie

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
-~--~~~~--~~--~--~---



Re: Admin Controller

2009-10-20 Thread Jon Bennett

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 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
-~--~~~~--~~--~--~---



RE: Admin Controller

2009-10-20 Thread Dave Maharaj :: WidePixels.com

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:jamie@gmail.com] 
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
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
-~--~~~~--~~--~--~---



Re: Admin Controller

2009-10-20 Thread adam

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
d...@widepixels.com 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:jamie@gmail.com]
 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
 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
-~--~~~~--~~--~--~---



Re: Admin Controller

2007-01-10 Thread Justin Johnson

If this is going to be the only action in the controller, then I would
use the pages controller.

simply add an admin() function in the pages controller and use the
following route

$Route-connect('/admin', array('controller' = 'pages','action' =
'index'))


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



Re: Admin Controller

2007-01-09 Thread Tijs Teulings


I think there is no magic to auto identify all the available admin actions.
What you are talking about would be kind of neat though...

Tijs


PaulV wrote:
 
 
 Hi,
 
 Having added CAKE_ADMIN functions to several controllers, I would like
 to add an action somewhere so that I can go to the URL /admin/ and get
 an interface screen containing all the various admin actions I can
 call.
 
 Is there a prefered place to put this admin action (do I have to create
 an admin controller and add a new route)?
 
 i.e.. $Route-connect('/admin', array('controller' = 'administrators',
 'action' = 'index'))
 
  class AdministratorsController extends AppController {
 
  var $name = 'Administrators';
  function index()
  }
 }
 
 Is there a way of automatically finding all the available admin actions
 and their respective controllers short of reading all the php files in
 and searching for the CAKE_ADMIN string in function definitions or do I
 have to manually pick out the available methods and define the action
 effectively statically?
 
Paul
 
 
  
 
 

-- 
View this message in context: 
http://www.nabble.com/Admin-Controller-tf2944794.html#a8236935
Sent from the CakePHP mailing list archive at Nabble.com.


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