使用 Zend,我试图找到为每个页面调用新 CSS 类的最有效方法。我宁愿不为每个页面创建新布局。我很好奇是否可以使用变量来更改类。
在我要使用的布局中:
<div id="main" class="<?php echo $header; ?>">
CSS 看起来像:
#main {
display:block;
min-width:960px;
}
#main.homeBG {
height:451px;
background:url(../img/images/home_bg.jpg) no-repeat center top;
}
#main.toolsBG {
height:451px;
background:url(../img/images/tools_bg.jpg) no-repeat center top;
}
所以不同的页面会有不同的BG图片。
我想做的是为每个 View 更改 Controller 操作中的 $header 变量。
class ToolsController extends ZendExtension_Controller_Action
{
/**
* Init
*/
public function init()
{
}
/**
* Default Index Action
*/
public function indexAction()
{
$header = $this->view->('toolsBG');
}
}
我知道这是错误的,但我将在此处使用它作为示例。
有什么办法可以做到这一点,还是我应该为每个 View 制作一个单独的布局页面?
谢谢。
最佳答案
我不喜欢 Zend Framework,但您是否尝试将 $header 变量设置为当前页面?如果是这样,请尝试使用 $_SERVER['REQUEST_URI']
(是的,丑陋)或者将其作为变量传递到您的 View 中?
关于php - 根据页面更改 CSS 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6750319/