views:

188

answers:

3

Sorry this is a pretty long question, but i want to have some disucssions here.

i am new to zend and try to avoid using modules as I think the view aspect of zend is pretty flexible and module will add extra directory and confusion. However i am wondering one thing. The app i am building is pretty big it actually has the modules concept in the app.

I know if using module, things can be more organised, where you can put modules in its own directory and have seperate view and controller etc.

however i decided to simulate module directory in the form of

--lang/module(in fact the controller)/controller(that's the action)/action(that's the child-action)/other-params/--

how we go about and do this kind of simulation

The initial idea i have is add another route to the application take the 4th param as the child-action. e.g

class some_controller extend extends Zend_Controller_Action{

public function someAction{

    switch (child-action) {
        case 'child-action1':
            ....... excute some action
            break;
        case 'child-action2':
            ....... excute some action
            break;....
    }

}

something like that. Does that make sense or if there's any other approach? and with this approach how we integrate Zend_ACL as how to add the 'fake child action' as a resource? Thank you.

+1  A: 

Perhaps you could set up your routes like so:

 /:controller/:action/:child-action

See here for more info on setting up routes.

Then in your action methods:

 $childAction = $this->getParam('child-action');

 // convert $childAction to camelCase.

 if(method_exists($this, $childAction))
 {
      // Check ACL
      $this->$childAction();
 }

Do not name child actions with the Action postfix as that would allow the actions to be called directly. You could maybe postfix them with something like 'fooChild' but not 'fooChildAction' as they would then map to 'foo-child'.

smack0007
Thanks for the help smack. That means in every action function we have to do these checks and forwarding. Any plugin or class extension that i can apply to get this checking carried out for all action controllers?
Dan
Are you going to be doing this for every single action in your app? If so, then why are you against modules? I can see why you might want to take this approach if you are only doing this for say a few actions in your app.You could make your own plugin and check in the preDispatch of the plugin for child actions and change the request accordingly.
smack0007
A: 

I think this is making it plenty more complicated then just working with the module directory structure... Which once set-up, is not that complicated at all, it's just a logical separation of classes...

Nicky De Maeyer
If he only wants to do this for a few actions in his app I can see why this approach may be desirable.
smack0007
A: 

It would make more sense to add a route ;)

have :module/:controller/:action/ -> admin/posts/add

and :module/posts/add/:action -> admin/posts/add/concept that would link to PostsAddController::ConceptAction();

better than switch statement i guess ;) But you can use it to... case "sth": $this->_forward('my-action','my-controller');

Tomáš Fejfar