S L
S L

Reputation: 14328

How to access controller name and action name form layout file in zend framework

I know to how to get controller name and action name from layout.phtml file so that i can make dynamic css.

Upvotes: 15

Views: 21771

Answers (4)

Ashley
Ashley

Reputation: 5957

Try this:

Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
Zend_Controller_Front::getInstance()->getRequest()->getActionName();

Upvotes: 45

Deepanshu
Deepanshu

Reputation: 21

<?php 
echo $this->headLink()->appendStylesheet($this >baseUrl().'path to your css file without public folder'); 
?>

Upvotes: -1

Deepanshu
Deepanshu

Reputation: 21

for finding controller name and action name in zend use this in controller

   Zend_Controller_Front::getInstance()->getRequest()->getControllerName()
   Zend_Controller_Front::getInstance()->getRequest()->getActionName()

Upvotes: 0

mapsi
mapsi

Reputation: 644

You shouldn't really have logic in your layout.

Best inject your css from your controller using the headlink container.

So in your controller...

$this->view->headLink()->appendStylesheet('custom_stylesheet.css');

And in your layout...

echo $this->headLink();

Simple as that! :)

Upvotes: 6

Related Questions