On Tue, Apr 24, 2012 at 8:12 PM, bs28723
<bill.sto...@boosterwebsolutions.com> wrote:
> Thanks for the reply.  It just seems like I am putting 100 functions in the
> one controller and a 100 views in the one folder. Just managing the code and
> the single file could get complicated.

Then you should probably be breaking things up a bit.

Also, keep in mind that it's always better to put as much code into
your models rather than the controllers. You can always call its
methods by $this->Model1->Model2->doSomething() if they're associated.

> But from a user experience, they are managing the organization. These are
> just areas to manage.

Yet in some case, you'll be managing a specific Member. There
shouldn't really be any need to do so from the
OrganizationsController. For listing all of the Members within an Org,
sure. But then to edit one of them, you can go to the
MembersController. Once saved, redirect back to the
OrganizationsController.

Router::connect(
        '/admin/orgs/:id',
        array(
                'admin' => 1,
                'controller' => 'organizations',
                'action' => 'view'
        ),
        array('id' => '[0-9]+', 'pass' => array('id'))
);

public function admin_view($id = null)
{
        // pull data for some org
}

Router::connect(
        '/admin/orgs/:id/members',
        array(
                'admin' => 1,
                'controller' => 'organizations',
                'action' => 'members'
        ),
        array('id' => '[0-9]+', 'pass' => array('id'))
);

public function admin_members($id = null)
{
        // pull data for some org and list members
}

When you list the members, create a link pointing to the MembersController:

foreach($data['Member'] as $member) {
        $this->Html->link(
                $member['name'],
                array(
                        'admin' => 1,
                        'controller' => 'members',
                        'action' => 'edit',
                        'id' => $member['id']
                ),
                array('title' => 'edit this member')
        );
}
        

Router::connect(
        '/admin/members/edit/:id',
        array(
                'admin' => 1,
                'controller' => 'members',
                'action' => 'edit'
        ),
        array('id' => '[0-9]+', 'pass' => array('id'))
);

public function admin_edit($id = null)
{
        // validate and save ...
        
        // redirect back to org's member list
        $route = array(
                'admin' => 1,
                'controller' => 'organizations',
                'action' => 'members',
                'id' => $this->request->data['Member']['organization_id']
        );
        $this->redirect($route);
}

> So, maybe my question should be...
>
> What is a better way to manage the code?  Maybe I should create components
> to manage the code related to a Model?

No, don't do that. If you start creating components to handle
model-specific tasks then you'd definitely be going in the wrong
direction.

Also, it's difficult to tell by just seeing the model names and not
the entire schema, but my hunch is that you might be able to normalize
things so that you have fewer models overall. But that really depends
on what exactly you need to do.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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

Reply via email to