James Hartford wrote:
> I am trying to get the controller, action, and params from the bootstrap
> file but can't figure out how to access them, I saw the getControllerName()
> method in the docs but there isn't much indication on how to use it. It
> would be nice to be able to use something like the following so that I can
> easily implement a custom access control structure that will set the
> controller/action to an error page if a user does not have access, but
> first
> need to be able to know the controller, action and params from the
> bootstrap
> file. Thanks for any help.
>
> $controller = Zend_Controller_Front::getInstance();
> $controller->setControllerDirectory('controllers/');
> echo $controller->getControllerName();
> $controller->dispatch();
Your best bet is going to be to write a plugin for the front controller
I think ( though I don't know if any of that is changing with the new
router coming in 0.1.4 ).
You'd put your access check probably in the preDispatch handler so that
it would be check prior to the target being called and you could change
the target. I do this to see if they are logged in before hitting
certain pages. If they are, it returns their current action. If not,
it returns an action aiming for the error controller, general action,
with appropriate message.
public function preDispatch($action) {
// snipping bit of code to check
// if page they are going to is on the no-login list
// check that they are logged in
switch (UserIsLoggedIn()) {
case USER_LOGGED_IN:
// they are logged in, so let the dispatch go
return $action;
break;
case NOT_LOGGED_IN:
return new Zend_Controller_Dispatcher_Token
('error','general',
array('message' =>
getMessage('ERROR_NOT_LOGGED_IN'));
case SESSION_EXPIRED:
return new Zend_Controller_Dispatcher_Token
('error','general',
array('message' =>
getMessage('ERROR_SESSION_EXPIRED'));
break;
default:
return new Zend_Controller_Dispatcher_Token
('error','general');
}
}
}
My apologies for the crap formatting.. hope it makes sense in your mailer.
Michael