views:

76

answers:

1

I am making a customer portal application using ZF. And the portal needs to work for different company brands. So I need to use all of the same backend code/controllers/etc, but dynamically change the view directory based off of the hostname.

Right now my view directory structure looks something like this:

/application/views/scripts/brand1/
/application/views/scripts/brand1/index/index.phtml
/application/views/scripts/brand1/error/error.phtml
/application/views/scripts/brand2/
/application/views/scripts/brand2/index/index.phtml
/application/views/scripts/brand2/error/error.phtml
/application/views/scripts/brand3/
/application/views/scripts/brand3/index/index.phtml
/application/views/scripts/brand3/error/error.phtml
and so on.

I am using the addScriptPath() function in bootstrap.php like so

protected function _initView()
{
    $view = new Zend_View();
    $view->doctype('XHTML1_STRICT');
 $view->env = APPLICATION_ENV;
 $view->addScriptPath(APPLICATION_PATH . '/views/scripts/brand1');
    $view->addHelperPath(APPLICATION_PATH . '/views/helpers');

    ...
}

However when this is run, it is looking for all views using /views/scripts/brand1/(action).phtml instead of looking for views using the correct scheme /view/scripts/brand1/(controller)/(action).phtml

tl;dr is it possible to dynamically choose the view directory and have it work like the default /views/scripts/(controller)/(action).phtml behavior?

+1  A: 

I knew I would find the answer after I posted here. In case anyone else encounters the same problem, the solution was using:

$view->setBasePath(APPLICATION_PATH . '/views/brand1');

And then modifying the directory structure to:

/application/views/brand1/scripts/...
Mark