gpt4 book ai didi

jquery - 删除 cakephp 默认模板中的额外代码

转载 作者:太空宇宙 更新时间:2023-11-04 13:37:13 26 4
gpt4 key购买 nike

我正在用 cakephp 构建一个应用程序,它下面有管理员和用户。 我为两者制作了不同的菜单。管理员可以查看所有菜单标题,但是 用户只有少数。我写了代码,但我不认为这是优化的方法 对于默认 View 。你能为它建议任何小方法吗,代码优化

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

并在管理部分添加额外的选项卡。请建议我适当的方法。

最佳答案

我只能建议将您的手册放入一个数组中:

$menu = array( 
'item1' => array(
'title' => 'Add Parcel',
'controller' => 'manageParcels',
'action' => 'addParcel',
'admin' => false,
// other fields used in menu
),
'item1' => array(
'title' => 'Add Consignment',
'controller' => 'manageConsignmens',
'action' => 'addConsignmen'
'admin' => true,
// other fields used in menu
)
)

这样你就可以遍历数组并动态地创建你的菜单

你也可以为你的数组创建一个树结构来考虑子菜单

下一步可能是创建一个 MenuHelper 来管理所有

最后一步可能是将菜单保存在数据库中的表(即 menu_items)中,创建一个充当树的模型。最后将所有内容放入一个插件中。

我想有些东西已经存在了

关于jquery - 删除 cakephp 默认模板中的额外代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22961330/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com