如果在元素(/view/element/myfile.ctp)中进行循环,以检查是否为admin或member

时间:2014-07-20 02:36:43

标签: cakephp-1.3 cakephp-2.1

我尝试在文件' /view/top-menu.ctp'中进行循环。 (top-menu.ctp)...根据角色显示链接 例如:

If (roles == Admin) { // I m looking for this condtion ? <a href='…..'> Admin </ a> }

1 个答案:

答案 0 :(得分:0)

In your loop condition you can write:

<?php if($variable['Model']['field'] == 'Admin'){ ?>
        <a href="<?php echo $this->webroot; ?>Controller/function"> Admin </ a>

<?php }else if($variable['Model']['field'] == 'User'){ ?>

<a href="<?php echo $this->webroot; ?>Controller/function">User</ a>

<?php } ?>