Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
So I have my main controllers all set up, but the action for the nav and some other modules belong solely to the layout alone. So I have this little snippet at the beginning of the actions that checks to see the source of the request and ensure that it's an action request and not a direct request.
$request = $this->getRequest();
if ($request->getParam('module') == $request->getModuleName()
&& $request->getParam('controller') == $request->getControllerName()
&& $request->getParam('action') == $request->getActionName()) {
// direct call to an actionStack-only action.
$this->_helper->redirector->gotoRouteAndExit(array(), null, true);
}
Now this is all fine and dandy, but it seems like this snippet should show up enough that I can find a better way to bring this into my other controllers. I know the view has view helpers that are automatically loaded when the viewRenderer is called, but is there something I can maybe introduce into the actionStack or just preload it somewhere else?
I would look into Front Controller plugins. You create a plugin class that overrides a method that corresponds to an event, in your case your plugin would most likely implement a preDispatch() method ( event handler ) that performed that behavior. I don't get what your plugin actually does though, what do you mean by direct request ??
Edit: ah nvm, I see "actionstack only", makes sense.
josh wrote:I would look into Front Controller plugins. You create a plugin class that overrides a method that corresponds to an event, in your case your plugin would most likely implement a preDispatch() method ( event handler ) that performed that behavior. I don't get what your plugin actually does though, what do you mean by direct request ??
Edit: ah nvm, I see "actionstack only", makes sense.
I think I get what you mean. I provide the method to the FC so at dispatch the function becomes available to every controller and then I can just call it at will....right?
Ok, but if I put a method right before the dispatch then every method would receive the check and that would break my entire app because not every action is a stack request. How could I tell it to validate only the methods I need it to?