Jump to content

rendering views without corresponding controller actions


brianlange

Recommended Posts

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);	
    	}
    	
    }

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);
     
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.