2
votes

As I said in a different post, I'm trying to adapt an open source intranet to my needs. One of the things I'm trying to do is make the intranet look for the view templates in a different folder than the default ($customViewPath and $defaultViewPath, from now on).

I'm totally unexperienced with Zend Framework and I'm having a hard time figuring some things out, but with this one I think I have come to a dead end.

What I'm trying is to add my custom path for the view templates by using $view->addScriptPath($customViewPath) in the bootstrap. Actually, it works, but only if the view file doesn't exist in $defaultViewPath. What I want is just the opposite: if a custom file doesn't exist in $customViewPath, load the default view from $defaultViewPath.

If I print getScriptPaths(), I get array($defaultViewPath, $customViewPath). That is, somewhere in the life cycle of the script, $defaultViewPath is added to the list of view paths with a higher priority than my custom path. I can't find where this happens, and don't think it is in every module controller.

Also, I know I must move my piece of code $view->addScriptPath($customViewPath) somewhere outside the bootstrap, since the custom path is module related, but I can't access the module name from my bootstrap because request hasn't been initiated yet. I guess I could change that, but I would like to keep the original behaviour as much as possible.

I have read every bit of info about addScriptPath(), setScriptPath(), getScriptPaths() I could understand, but still have no idea on how to apply that to my case. Any idea will be welcome.

I'm aware I should provide more information about the application, but my lack of experience makes me not know what else can be necessary. Please feel free to ask for anything that could make my problem clearer.

The code of the application can be downloaded from its web. I just don't post the link here so that it doesn't look like spam.

Edit:

I'm sorry to insist on this topic, but the more I learn about ZF the more puzzled I am with the issue.

I have traced the stack of view paths, and somewhere between my plugin preDispatch() and the action preDispatch() functions, the default path (the one I'm trying to override) is pushed into the stack.

The only thing I can think of is some other plugin is being executed after mine. I have tried to give my plugin a very high execution order number, but still nothing.

I'm not exaggerating if I say that I have spent at least two weeks on this issue (tho I can't afford to spend more time on this at work, I am spendin a lot at home), I have read everything I could put my hands on about the dispatch cycle, but I don't know what to try next.

Just in case I may be right, is there any way to list from an action what plugins are being executed and their order?

1

1 Answers

2
votes

Basically you have reverse the order of the path stack.

Try:

protected function _initView()
    {
        //Initialize view
        $view = new Zend_View();

        //reset script path stack with custom view path
        $view->setScriptPath($customViewPath);
        //add default path back to path stack
        $view->addScriptPath($defaultViewPath);

        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
                'ViewRenderer');
        $viewRenderer->setView($view);
        //Return it, so that it can be stored by the bootstrap
        return $view;
    }

this should accomplish pretty much what you are looking for.