laravel 4请求旁边的通配符有哪些支持模式?

问题描述 投票:1回答:1

基于documentation

确定请求路径是否匹配模式

if (Request::is('admin/*'))
// What are the support patterns in laravel 4 request beside the wildcard?
{
  //
}

我似乎无法找到提供更多示例而不仅仅是通配符的文档。

php laravel laravel-4
1个回答
6
投票

伙计们,我其实想要切换活动菜单css

在这种情况下:

{{ (Request::is('home')) ? 'active' : '' }}

要么

{{ (Request::segment(1) == 'home') ? 'active' : '' }}

要么

{{ (Request::path() == 'home/special') ? 'active' : '' }}

或自己做

{{ (preg_match('whatever you want here', Request::path()) ? 'active' : '') }}

编辑:查看Laravel核心中的Request :: is()函数:

/**
     * Determine if the current request URI matches a pattern.
     *
     * @param  string  $pattern
     * @return bool
     */
    public function is($pattern)
    {
        foreach (func_get_args() as $pattern)
        {
            if (str_is($pattern, $this->path()))
            {
                return true;
            }
        }

        return false;
    }

所以你实际上可以传入任何'模式',它会匹配str_is()

© www.soinside.com 2019 - 2024. All rights reserved.