2008年9月23日星期二

Re: [fw-mvc] should isDispatchable check if the action exists?

retoreto wrote:
>
> // Check for default controller
> if ($request->getControllerName() ==
> $dispatcher->getDefaultControllerName()) {
> return true;
> }
>

Uh I just realized how strange the first checking block was ("check for
default controller").
Here is a new version with that part removed but instead only looking for
the controller-class in the controller directory of the requested module.

/**
* Return whether a given request (module-controller-action) exists
*
* @param Zend_Controller_Request_Abstract $request Request to check
* @return boolean Whether the action exists
*/
private function _actionExists($request) {
$dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();

// Check controller
if (!$dispatcher->isDispatchable($request)) {
return false;
}

// Check action
$controllerClassName = $dispatcher->formatControllerName(
$request->getControllerName() );
$controllerClassFile = $controllerClassName . '.php';
if ($request->getModuleName() != $dispatcher->getDefaultModule()) {
$controllerClassName = ucfirst($request->getModuleName()) . '_' .
$controllerClassName;
}
try {
require_once 'Zend/Loader.php';
Zend_Loader::loadFile($controllerClassFile,
$dispatcher->getControllerDirectory($request->getModuleName()));
$actionMethodName =
$dispatcher->formatActionName($request->getActionName());
if (@in_array($actionMethodName,
get_class_methods($controllerClassName))) {
return true;
}
return false;
} catch(Exception $e) {
return false;
}
}

Sincerely,
reto
--
View this message in context: http://www.nabble.com/should-isDispatchable-check-if-the-action-exists--tp15648297p19635140.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: