brianlange Posted November 21, 2010 Share Posted November 21, 2010 I have a zf site with a lot of views that are simple html files. I dont want to have to create a controller action function for every one of the views. This is my preDispatch function. The view renders okay but theres an error about zf not finding the controller action. Also, I am using get_class_methods to determine which controller actions exist. Is there a better way to do this? public function preDispatch() { $class_methods = array_flip(get_class_methods('IndexController')); $viewScript = $this->_request->getActionName(); $function = $viewScript . 'Action'; if (!array_key_exists($function, $class_methods)) { $this->render($viewScript); } } Quote Link to comment https://forums.phpfreaks.com/topic/219388-rendering-views-without-corresponding-controller-actions/ Share on other sites More sharing options...
brianlange Posted November 21, 2010 Author Share Posted November 21, 2010 I added a _call function to the controller. It appears to get the job done. Is there a better way? public function __call($name, $arguments) { $viewScript = substr($name, 0, strpos($name, 'Action')); $this->render($viewScript); } Quote Link to comment https://forums.phpfreaks.com/topic/219388-rendering-views-without-corresponding-controller-actions/#findComment-1137601 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.