Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CodeIgniter:如何将当前的_url与视图url匹配(构建导航)_Php_Codeigniter_Url_Base Url - Fatal编程技术网

Php CodeIgniter:如何将当前的_url与视图url匹配(构建导航)

Php CodeIgniter:如何将当前的_url与视图url匹配(构建导航),php,codeigniter,url,base-url,Php,Codeigniter,Url,Base Url,以便将活动类应用于导航菜单中的当前项。我需要检查它的链接是否等于URL 我试着这样做: <ul class="nav"> <li class="<?php if(uri_string(current_url()) == base_url() || uri_string(current_url()) == '') echo 'active'; ?>"> <a href="<?php echo base_url() ?>

以便将活动类应用于导航菜单中的当前项。我需要检查它的链接是否等于URL

我试着这样做:

<ul class="nav">
    <li class="<?php if(uri_string(current_url()) == base_url() || uri_string(current_url()) == '') echo 'active'; ?>">
         <a href="<?php echo base_url() ?>">Home</a>
    </li>
    <li class="<?php if(uri_string(current_url()) == base_url('news/create/')) echo 'active'; ?>">
        <a href="<?php echo base_url('news/create/') ?>">+ New</a>
    </li>
</ul>
威奇似乎和家里的人相处得很好

但在新闻/创作中,它们永远不会平等

它将news/create uri\u stringcurrent\u url与/news/create base\u url'news/create'进行比较

所以。。这个问题怎么办?

试试这个

<ul class="nav">
    <li class="<?php if(! $this->uri->segment(1) || $this->uri->segment(1) == 'welcome') echo 'active'; ?>">
         <a href="<?php echo base_url() ?>">Home</a>
    </li>
    <li class="<?php if($this->uri->segment(1) == 'news' && $this->uri->segment(2) == 'create' ) echo 'active'; ?>">
        <a href="<?php echo base_url('news/create/') ?>">+ New</a>
    </li>
</ul>
试试这个

<ul class="nav">
    <li class="<?php if(! $this->uri->segment(1) || $this->uri->segment(1) == 'welcome') echo 'active'; ?>">
         <a href="<?php echo base_url() ?>">Home</a>
    </li>
    <li class="<?php if($this->uri->segment(1) == 'news' && $this->uri->segment(2) == 'create' ) echo 'active'; ?>">
        <a href="<?php echo base_url('news/create/') ?>">+ New</a>
    </li>
</ul>

正如我所说,一个干净简单的解决方案:

if($this->uri->uri_string() == 'news/create'){ ...

正如我所说,一个干净简单的解决方案:

if($this->uri->uri_string() == 'news/create'){ ...

这很简单。。这才是最重要的;我确实同意他/她。您只需要知道调用了哪个控制器和操作!上面我的建议是,如果$this->uri->uri_string=='news/create'稍微不那么凌乱,那么它很简单。。这才是最重要的;我确实同意他/她。您只需要知道调用了哪个控制器和操作!上面我的建议是,如果$this->uri->uri\u string=='news/create'稍微不那么凌乱,为什么不直接做呢!将其作为答案发布刚才发布的答案是:如果$this->uri->uri\u string=='news/create',我觉得更干净,为什么不这样做呢!将其作为答案发布刚才发布了答案: