tags:

views:

536

answers:

2

My situation:

The user is presented with a table or list of items. Beside each item they can click a checkbox to select it, and then at the bottom is a select box which says "With selected items...", and things like "delete", "move to project", "download", etc. You know the deal - bulk operations. Some of the operations will execute immediately and don't require their own view, however others will need an intermediate view (eg: "Move these to which project?").

Since each of the individual operations is handled by a different action (and different controller, possibly), but forms can only post to one address, I need an action which will take the posted data and dispatch it to the appropriate place.

Using redirect() will not work either, since this will need to be AJAX'd in the near future.

Basically I just want an action which will delegate to a different controller/action as if that were the original request: maintaining post data, rendering that view, etc.

Any ideas?

A: 

If you follow MVC design pattern, you'll have no problem with that, since the business logic should be in the Models, not the Controller actions.

Anyway, you can create a "bulk" action wich will call all the others searching for some data to work with.

yoda
yep - how do I do that? How do I call a different action on a different controller?
nickf
"call", per say, isn't very recommended. But you can instantiate the desired controllers inside the first one. Still, the best option is to have Models doing that work, and having a single controller action bulk(), for example. Things will be much more easy to handle when you port to ajax, btw
yoda
+2  A: 

I was able to figure it out using the Dispatcher.

// for example, to reroute to users/delete

// this is in the controller which receives the request.
// this could even be in the AppController

$this->autoRender = false;
$d = new Dispatcher();
$d->dispatch(
    array("controller" => "users", "action" => "delete"),
    array("data" => $this->data)
);
nickf