2011年3月4日星期五

[fw-mvc] troubles with custom view-scripts location and noViewRender=true by default

Been having a nightmare trying to use a completely custom view scripts
location, combined with having noViewRenderer=true by default in
Zend_Controller_Front, but then switching it on for certain action
controllers via a routeShutdown plugin hook.

I'm know the noViewRenderer param gets passed through to the dispatcher,
hence toggling it at the routeShutdown stage. I can test at various other
points below the dispatcher (i.e. in the action controller) that if I've set
noViewRenderer=false, this appears to persist down to the action controller
level.

I want to set a completely custom path to my view scripts, so I can't use
the default view scenario which gets set up by the viewRenderer action
helper, as it seems to test for the presence of a view scripts folder
according to the 'stock' folder structure.

So I tied replacing the initView() method of my action controller thus:

public function initView () {

$this->view = new Zend_View(array('basePath' => APPLICATION_PATH .
'/custom/path/to/views/'));

$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
$this->_helper->addHelper($viewRenderer); // even slightly on track?!?!

return $this->view;
}

I'm then trying all sorts in my action method to try and get the view
working. I can get the view scripts loaded and rendered no problem. But
whatever I try, the view object that my view script sees somehow doesn't
have any of the vars I've assigned it in the controller - i.e. it looks to
be a different view object altogether..

public function indexAction () {

$this->initView(); // tried both with and without this, in various
permutations
$this->view->myvar = 'hello world';

$this->view->render('somescript'); // tried this, with or without .phtml
// OR
$this->render(); // ..also tried this
}

The direct Zend_Controller_Action::render() version seems to use code within
the viewRenderer helper to work out what view script it should load, and
whether it exists or not. Conversely, the $this->view->render() approach
uses the view object's native methods to do the same. Neither is playing
ball for me it would seem. Things might go wrong within the ::_script()
private method of the Zend_View_Abstract class from my extensive
problem-hunting (stab in the dark) investigations.

Can anyone help?

I basically want to:

- have noViewRenderer=true (M & C, but no V) by default, but for selected
actions/controllers I need to use a view and view scripts
- have completely custom paths to where my view scripts are located in my
bespoke folder structure

...can it be that hard?

Jon

--
View this message in context: http://zend-framework-community.634137.n4.nabble.com/troubles-with-custom-view-scripts-location-and-noViewRender-true-by-default-tp3335661p3335661.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: