下面是我的default.ctp文件。我的问题是如何从另一个视图或页面更改class="post-content"?
<main class="main-content">
<div class="post-content">
<?php echo $this->Session->flash(); ?>
<?php echo $this->fetch('content'); ?>
</div>
</main>发布于 2015-05-15 17:38:17
在布局中,可以将静态类更改为包含下面所示的一个简单if/ you语句:
<main class="main-content">
<div class="<?php echo (isset($layout_class_var)) ? $layout_class_var : 'post-content'; ?>">
<?php echo $this->Session->flash(); ?>
<?php echo $this->fetch('content'); ?>
</div>
</main>然后,每次您想要设置一个新的类名来代替默认的类post-时,只需将所需的类名设置为控制器操作中的变量:
public function someAction() {
//set layout class to 'new-layout-class'
$this->set('layout_class_var', 'new-layout-class');
}https://stackoverflow.com/questions/30263896
复制相似问题