一个只返回 css 类的辅助方法怎么样,你从控制器调用它,然后将 css 值传递给视图?
class YourController {
public function yourpageAction(){
// do your stuff, then call your helper
$this->view->bodyCssClass = $this->setcss();
}
protected function setcss(){
// analyse here all the parameter you wish (route, name, id etc.)
// and just return the correct css string
return $css;
}
}
你甚至可以使用“init()”方法来自动调用你的“setcss”方法(或者任何你给它的名字)。更进一步,您可以扩展 Zend Controller 类,并让所有控制器扩展您的特定控制器:所有页面都将继承这个 css 定义过程。它有助于维护和阅读您的代码。
在您看来,只是一个简单的调用:
<body class="<?php echo $this->bodyCssClass;">