Hi Jens!
What I did was a more generic way of changing the action depending on
the request method. I extend Zend_Controller_Action to change
dispatch():
public function dispatch($action)
{
$method = !empty($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER
['REQUEST_METHOD']) : 'get';
if (method_exists($this, $action . $method)) {
parent::dispatch($action . $method);
} else {
parent::dispatch($action);
}
}
If I have a method called indexActionGet() or indexActionPost() it
gets called if the request method matches. If not indexAction() is
called (or __call() if it doesn't exist).
Maybe I should add a task as feature request. It's quite common.
nico
[07.06.2007 23:05] Jens Ruben wrote:
Hello!
I’m very new to the zend framework and I’ve tried to write a
Controller_Plugin to reroute post requests. Whenever a user submits
a form I’d like to check, if there’s a method called
$action.’Validate’ - if yes, call it, check the result and reroute
the request to a method called $action.’Submit’
Here’s my code but I think there should be a much better solution
for this task.
class Buys_Controller_Plugin_ReroutePostRequest extends
Zend_Controller_Plugin_Abstract
{
public function preDispatch($request)
{
if(!$request->isPost()) {
return;
}
$response = Zend_Controller_Front::getInstance()->getResponse();
$dispatcher = Zend_Controller_Front::getInstance()-
>getDispatcher();
$controller = $dispatcher->loadClass(
$dispatcher->getControllerClass($request)
);
$action = $request->action;
$actionValidate = $action.'Validate';
if(method_exists($controller, $actionValidate)) {
$method = $action.'Submit';
$obj = new $controller($request, $response);
$result = $obj->{$actionValidate}();
if($result && method_exists($controller, $method)) {
$request->setActionName($action.'-Submit');
}
}
}
}
Thanks in advance,
Jens
--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail