gpt4 book ai didi

cakephp - 更改 default.ctp 中的特定类

转载 作者:行者123 更新时间:2023-12-02 01:37:36 25 4
gpt4 key购买 nike

下面是我的default.ctp 文件。我的问题是我该如何改变 class="post-content" 来自另一个 View 或页面?

   <main class="main-content">
<div class="post-content">
<?php echo $this->Session->flash(); ?>
<?php echo $this->fetch('content'); ?>
</div>
</main>

最佳答案

在您的布局中,您可以更改静态类以包含如下所示的简单 if/else 语句:

<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-content时,只需将所需的类名设置到$layout_class_var变量中你的 Controller Action :

public function someAction() {
//set layout class to 'new-layout-class'
$this->set('layout_class_var', 'new-layout-class');
}

关于cakephp - 更改 default.ctp 中的特定类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30263896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com