I am building a app in cakephp which have admin and users under it. I have make different menu for both . admin can view all menu title but users only few. I have written code, but i don't think this is optimized approach for default view.Can you suggest any small approach for it , Code optimization
here is my code:
<?php
if ($this->Session->read('Auth.User')){
if($this->Session->read('Auth.User.role')=='admin')
{
?>
Admin Section
<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 }
Other User Section
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
and in admin section add extra tab .Please suggest me appropriate approach.