我正在cakephp中建立一個應用程序,該應用程序具有管理員和用戶。 我爲兩者製作了不同的菜單。管理員可以查看所有菜單標題,但 用戶只有幾個。我已經寫代碼,但我不認爲view.Can你認爲它的任何小的方法,代碼優化刪除cakephp默認模板中的額外代碼
here is my code:
<?php
if ($this->Session->read('Auth.User')){
if($this->Session->read('Auth.User.role')=='admin')
{
?>
管理部分
<div id='cssmenu'>
<ul>
<li class='active'><?php echo $this->Html->link(
'Home',
array(
'controller' => 'users',
'action' => 'index',
'full_base' => true
));?></li>
<li class='has-sub'><a href='#'><span>Manage Users</span></a>
<ul>
<li class='has-sub'><?php echo $this->Html->link(
'Add New User',
array(
'controller' => 'users',
'action' => 'add',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'InActive Users List',
array(
'controller' => 'users',
'action' => 'listUserInActive',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'Active Users',
array(
'controller' => 'manageUsers',
'action' => 'listUserActive',
'full_base' => true
));?>
</li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Manage Consignment</span></a>
<ul>
<li class='has-sub'><?php echo $this->Html->link(
'Add Consignment',
array(
'controller' => 'manageConsignments',
'action' => 'addConsignment',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'Consignment List',
array(
'controller' => 'manageConsignments',
'action' => 'listConsignment',
'full_base' => true
));?>
</li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Manage Parcels </span></a>
<ul>
<li class='has-sub'><?php echo $this->Html->link(
'Add Parcel',
array(
'controller' => 'manageParcels',
'action' => 'addParcel',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'Parcel List',
array(
'controller' => 'manageParcels',
'action' => 'listParcel',
'full_base' => true
));?>
</li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Manage Pallets </span></a>
<ul>
<li class='has-sub'><?php echo $this->Html->link(
'Add Pallets',
array(
'controller' => 'managePallets',
'action' => 'addPallet',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'Pallets List',
array(
'controller' => 'managePallets',
'action' => 'listPallet',
'full_base' => true
));?>
</li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Manage Profile </span></a>
<ul>
<li class='has-sub'><?php echo $this->Html->link(
'Update Profile',
array(
'controller' => 'users',
'action' => 'editProfile',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'Update Password',
array(
'controller' => 'users',
'action' => 'updatePassword',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'Delete Account',
array(
'controller' => 'users',
'action' => 'delete',
'full_base' => true
),
array(),
"Are you sure you wish to delete this Account?");?>
</li>
</ul>
</li>
<li><?php echo $this->Html->link(
'Logout',
array(
'controller' => 'users',
'action' => 'logout',
'full_base' => true
));?>
</ul>
</div>
<?php }
這是最佳進場 默認
其他用戶部分
else {?>
<div id='cssmenu'>
<ul>
<li class='active'><?php echo $this->Html->link(
'Home',
array(
'controller' => 'users',
'action' => 'index',
'full_base' => true
));?></li>
<li class='has-sub'><a href='#'><span>Manage Consignment</span></a>
<ul>
<li class='has-sub'><?php echo $this->Html->link(
'Add Consignment',
array(
'controller' => 'manageConsignments',
'action' => 'addConsignment',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'Consignment List',
array(
'controller' => 'manageConsignments',
'action' => 'listConsignment',
'full_base' => true
));?>
</li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Manage Parcels </span></a>
<ul>
<li class='has-sub'><?php echo $this->Html->link(
'Add Parcel',
array(
'controller' => 'manageParcels',
'action' => 'addParcel',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'Parcel List',
array(
'controller' => 'manageParcels',
'action' => 'listParcel',
'full_base' => true
));?>
</li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Manage Pallets </span></a>
<ul>
<li class='has-sub'><?php echo $this->Html->link(
'Add Pallets',
array(
'controller' => 'managePallets',
'action' => 'addPallet',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'Pallets List',
array(
'controller' => 'managePallets',
'action' => 'listPallet',
'full_base' => true
));?>
</li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Manage Profile </span></a>
<ul>
<li class='has-sub'><?php echo $this->Html->link(
'Update Profile',
array(
'controller' => 'users',
'action' => 'editProfile',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'Update Password',
array(
'controller' => 'users',
'action' => 'updatePassword',
'full_base' => true
));?>
</li>
<li class='has-sub'><?php echo $this->Html->link(
'Delete Account',
array(
'controller' => 'users',
'action' => 'delete',
'full_base' => true
),
array(),
"Are you sure you wish to delete this Account?");?>
</li>
</ul>
</li>
<li><?php echo $this->Html->link(
'Logout',
array(
'controller' => 'users',
'action' => 'logout',
'full_base' => true
));?>
</ul>
</div>
So can i create like oops concept so that which tabs are common
to all that are added in else
並在管理部分添加額外的選項卡。請提示我適當的方法。
看看ACL模式以瞭解如何實現這一點。我建議你在db中製作菜單,並將每個項目授予用戶類型。當你製作你的樹結構時,請看這個http://stackoverflow.com/questions/22785181/build-a-tree-menu-with-li-tag-from-array讓你的樹形菜單 – Fury