When I originally built my website, it was handling only one interface, but now I need to handle man开发者_Go百科y interfaces.
I can detect which site to send for each request and isolate each site from the others, but all the sites have the same views.
Is there a way that I can render different views from the same controller?
I'm thinking something like:
application
controller
model
site_1_view
site_2_view
Is this possible?
$this->view->render('script.phtml');
should work.
Or:
public function myAction()
{
return $this->otherAction();
}
public function otherAction()
{
}
add a new scripts path to view LIFO stack
Just an idea: detect what site is currently being viewed, and then tell Zend_View to use scripts for that specific site by setting $view->setScriptPath(/path/to/site1/scripts/);
Edit: I might be wrong on this one, but the best place to set this would be a controller plugin in the preDispatch
method, as at that time, you would know what module/controller/action has been requested, but not yet dispatched: http://framework.zend.com/manual/en/zend.controller.plugins.html
It was very simple - I found that I could set the view base path in my constructor:
$this->view->setBasePath("../application/site_1_view/views");
So in public/index.php
, I detect the URL, set it in the session, detect the name from my DB, then use the name to set the base path:
$this->view->setBasePath("../application/".$siteName."/views");
So the application structure is now:
application
controllers
model
site_1_view
views
scripts
controllerName
ActionName
site_2_view
views
scripts
controllerName
ActionName
精彩评论