FWIW, I use a custom Router (based on the Rewrite Router) that does its routing
based on the combination of REQUEST_METHOD and REQUEST_URI (after the app's
baseUrl has been stripped). I read my routes in from a config file that roughly
looks like this:
<method> <url> <controller> <action>\n
Yes, I have one line in this file for every valid URL (or class of URLs) in my
system... :) This way, I easily get the requests to go straight to the actions
that will process them.
I'd second a feature request to add REQUEST_METHOD to the existing Router &
Route classes.
Regards,
Bryce Lohr
Nico Edtinger wrote:
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