如何在cakephp中进行if else / conditional划分

时间:2018-03-12 01:54:37

标签: php cakephp cakephp-3.0

如何在CakePHP中创建一个条件?

在WordPress中,我只能使用

loader = transforms.Compose([transforms.Resize((image_size)), transforms.ToTensor()])  # resize and convert to tensor
image = loader(image)
mean_pixel = torch.FloatTensor([123.68, 116.779, 103.939])
mean_pixel = mean_pixel.view(3, 1, 1).expand_as(image)
image.add(-mean_pixel)

1 个答案:

答案 0 :(得分:3)

由于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'): ?>

您可以在Controller中设置条件变量。