Zend Framework

Zend Form lacks a method to set the action based on a route

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Minor 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);
}

Activity

Hide
Wil Sinclair added a comment -

Please evaluate and categorize as necessary.

Show
Wil Sinclair added a comment - Please evaluate and categorize as necessary.
Hide
Matthew Weier O'Phinney added a comment -

Please use either the url action or view helper for this functionality; there's no reason to duplicate this logic yet again.

Show
Matthew Weier O'Phinney added a comment - Please use either the url action or view helper for this functionality; there's no reason to duplicate this logic yet again.

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: