【发布时间】:2015-10-10 17:40:11
【问题描述】:
我希望使用一个布局(sections.php)呈现不同的视图,但布局应该为每个视图加载不同的背景。在不为每个视图使用 4 种不同布局的情况下如何实现这一点。
受保护/观看次数/网站
-
- index.php
- 关于.php
- 产品.php
-brands.php
-
-sections.php
<html>
<head></head>
<body>
<div id= "viewname">
<ul>
<li>Home</li>
<li>about</li>
<li>products</li>
<li>brands</li>
</ul>
<!--I want to load different bg for this div for each view--->
<!--there's a lot of content that comes here, i dont want to do it in every page--->
<!--how can i load the class name for this div dynamically if possible-->
</div>
<div class=section-cont>
<?php echo $content; ?>
</div>
</body>
</html>
我的 CSS
#about
{
....
background-image: ('../img/about.jpg')
}
#product
{
....
background-image: ('../img/product.jpg')
}
#brands
{
....
background-image: ('../img/brands.jpg')
}
我的控制器
class SiteController extends Controller
{
public function actionAbout()
{
$this->layout = "sections";
$this->render('about');
}
//functions for other views is similar to above
【问题讨论】:
-
Yii.我投降。 _