Php 是否可以在特定URL的位置设置一些条件?

Php 是否可以在特定URL的位置设置一些条件?,php,codeigniter,Php,Codeigniter,我正在侧边栏中做活动。管理员登录后(当然,它会自动重定向到localhost:/xxx/admin/index或localhost:/xxx/admin/),并且活动服务器位于仪表板中。 当管理员单击用户管理(它将重定向到localhost:/xxx/admin/UserAccount)时,活动帐户将更改为用户管理/。。问题是,当特定的URL是that/this时,是否可以进行if语句 查看 <li class="<?= highlight_menu('Administrator/u

我正在侧边栏中做活动。管理员登录后(当然,它会自动重定向到localhost:/xxx/admin/index或localhost:/xxx/admin/),并且活动服务器位于仪表板中。 当管理员单击用户管理(它将重定向到localhost:/xxx/admin/UserAccount)时,活动帐户将更改为用户管理/。。问题是,当特定的URL是that/this时,是否可以进行if语句

查看

<li class="<?= highlight_menu('Administrator/userAccount',TRUE)?>treeview">
      <a href="#">
        <i class="fa fa-users"></i> <span>User Management</span>
        <span class="pull-right-container">
          <i class="fa fa-angle-left pull-right"></i>
        </span>
      </a>
      <ul class="treeview-menu">
        <li><a href="<?= base_url(). 'Administrator/userAccount'?>"><i class="fa fa-circle-o"></i> View users account</a></li>

      </ul>
    </li>

以下几行代码将帮助您根据当前URL突出显示菜单项。为了简单和可重用性,我将它作为一个助手函数添加到我的助手文件中。(我已经在application/helpers/common_helper.php中添加了一个helper文件,并在应用程序启动时自动加载)

在此处阅读有关帮助器函数的更多信息

然后在视图中,添加如下菜单项

<ul>
    <li class="menu_item">
        <a class="menu-class <?php echo highlight_menu('controller/method_name', TRUE);?>" href="<?php echo base_url('controller/method_name');?>">Menu Item</a>
    </li>
</ul>

在CSS中,使用
.active menu
选择器为活动菜单项添加样式。

您是否在谈论会话?您可以使用cookie或db列存储数据
ischeckedUserManagement
userStatus
在用户表中。根据其中一个,你可以很容易地确定你想重定向到哪里。对于此类问题,最好使用基于角色的登录和seision角色。我知道loggin会话,问题是,当特定的URL是此Admin/userAccount时,我应该如何放置活动侧栏?在哪里可以找到common_helper?@Angel您可以在应用程序/helpers文件夹中创建common_helper.php(common是任意名称),并在其中添加常用函数。阅读更多关于帮助程序的信息在调用这些函数之前不要忘记加载帮助程序文件我按照您对我说的说明进行操作输出是什么?在treeview之前添加一个空格,将css中活动菜单项的样式设置为。活动菜单{/**此处的样式**/}
function highlight_menu($menu_item, $has_routes = FALSE)
{
    $CI         = get_instance();
    if(! $has_routes) // activate only if the exact URL is found
        return (uri_string()==$menu_item) ? 'active-menu':'';
    $controller =   strtolower($CI->router->fetch_class());// get controller name
    $method     =   strtolower($CI->router->fetch_method()); // get method name
    return (strtolower($menu_item) == $controller."/".$method) ? 'active-menu' : ''; // activate only if the controller and method matches
}
<ul>
    <li class="menu_item">
        <a class="menu-class <?php echo highlight_menu('controller/method_name', TRUE);?>" href="<?php echo base_url('controller/method_name');?>">Menu Item</a>
    </li>
</ul>