You can get the current View from the ViewRenderer helper:
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view;
Pádraic Brady
http://blog.astrumfutura.com
http://www.survivethedeepend.com
OpenID Europe Foundation Irish Representative
From: whisher <whisher@mp4.it>
To: fw-mvc@lists.zend.com
Sent: Wednesday, September 16, 2009 10:20:29 AM
Subject: [fw-mvc] Zend_Controller_Plugin_Abstract how to get stylesheet links
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view;
http://blog.astrumfutura.com
http://www.survivethedeepend.com
OpenID Europe Foundation Irish Representative
From: whisher <whisher@mp4.it>
To: fw-mvc@lists.zend.com
Sent: Wednesday, September 16, 2009 10:20:29 AM
Subject: [fw-mvc] Zend_Controller_Plugin_Abstract how to get stylesheet links
Hi
I want to load a css/js file dynamically so I ended up with this code
public function postDispatch(Zend_Controller_Request_Abstract $request)
{
if (!$request->isDispatched()) {
return;
}
$controller = $request->getControllerName();
// ensure we don't add a link that already exists
$currentLinks = array();
var_dump(count($this->_view->headLink()));
foreach($this->_view->headLink() as $link)
{
if($link->rel == "stylesheet") {
$currentLinks[] = $link->href;
}
}
// screen
$file = $this->_view->baseUrl() . '/res/css/' . $controller . '.css';
if (file_exists($file)) {
$url = $this->_view->baseUrl() . '/res/css/' . $controller . '.css';
if(!in_array($url, $currentLinks)) {
$this->_view->headLink()->appendStylesheet($url , 'screen,projection');
}
}
}but I can't manage to count the existing links
Can you help me, please ?
Thanks in advance
Bye
View this message in context: Zend_Controller_Plugin_Abstract how to get stylesheet links
Sent from the Zend MVC mailing list archive at Nabble.com.
没有评论:
发表评论