Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: 1.5.2
-
Fix Version/s: None
-
Component/s: Zend_Form
-
Labels:None
Description
It would be nice if Zend Form supported setting the action based on a route registered with the router, this way the user doesn't have to either build the action url himself, or even use static urls. A simple method for it could look like:
/**
- set the action based on a route
* - @param array $params
- @param string $routeName
- @param bool $reset
*/
public function setRouteAction($params = array(), $routeName = null, $reset = false)
{
$frontController = Zend_Controller_Front::getInstance();
//the FC
$router = $frontController->getRouter();
//the router (assumes rewrite router)
if ($reset) {
$routeName = 'default';
}
//hmm... this may lead to unexpected results
//but so will getting the current route name
if ($routeName == null) {
try {
$routeName = $router->getCurrentRouteName();
} catch (Zend_Controller_Router_Exception $e) {
$routeName = 'default';
}
}
//requested routename/default
$route = $router->getRoute($routeName);
//the requested route
$action = rtrim($frontController->getBaseUrl(), '/');
$action .= '/' . $route->assemble($params, $reset);
$this->setAction($action);
}
Please evaluate and categorize as necessary.