如何在 cakephp 中制作和 if else / 条件除法
How to make and if else / conditional division in cakephp
如何在 CakePHP 中创建条件?
在 WordPress 中我只能使用
<?php if(is_page('1')){ ?>
<section id="flash-area">
<div class="flash oswald">
.....................
</div>
</section>
<?php }else {?>
//i will removed this div
<?php } ?>
由于 Wordpress 和 CakePHP 都是使用 PHP 构建的,您可以为此使用普通的 PHP。在您的模板文件中(例如 src/Template/Pages/home.ctp)执行:
<?php if ($condition) { ?>
<section id="flash-area">
<div class="flash oswald">
.....................
</div>
</section>
<?php } else { ?>
<div>Another div</div>
<?php } ?>
您还可以使用 alternative control structures 来获得更简洁的代码:
<?php if ($condition): ?>
<section id="flash-area">
<div class="flash oswald">
.....................
</div>
</section>
<?php endif; ?>
既然你没有写,你想测试哪个条件,我假设你想检查你是否在 PagesController 的特定(静态)页面上。您的条件看起来像:
<?php if ($page == 'home'): ?>
您可以在控制器中设置条件变量。
如何在 CakePHP 中创建条件?
在 WordPress 中我只能使用
<?php if(is_page('1')){ ?>
<section id="flash-area">
<div class="flash oswald">
.....................
</div>
</section>
<?php }else {?>
//i will removed this div
<?php } ?>
由于 Wordpress 和 CakePHP 都是使用 PHP 构建的,您可以为此使用普通的 PHP。在您的模板文件中(例如 src/Template/Pages/home.ctp)执行:
<?php if ($condition) { ?>
<section id="flash-area">
<div class="flash oswald">
.....................
</div>
</section>
<?php } else { ?>
<div>Another div</div>
<?php } ?>
您还可以使用 alternative control structures 来获得更简洁的代码:
<?php if ($condition): ?>
<section id="flash-area">
<div class="flash oswald">
.....................
</div>
</section>
<?php endif; ?>
既然你没有写,你想测试哪个条件,我假设你想检查你是否在 PagesController 的特定(静态)页面上。您的条件看起来像:
<?php if ($page == 'home'): ?>
您可以在控制器中设置条件变量。