在重用其他项目的代码时调用Laravel中的未定义函数

时间:2016-12-08 08:31:45

标签: php laravel blade

我有这个blade.php应该生成一个菜单:

<ul class="header-nav">
    @foreach(config('menu.horizontal') as $menu)
        <li class="{{set_active($menu['active'],'active')}}  @if(isset($menu['children'])) has-child @endif">
            <a href="{{$menu['link']}}" @if(isset($menu['children'])) data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" @endif><i class="{{$menu['icon']}}"></i> {{$menu['title']}}</a>
            @if(isset($menu['children']))
                <div class="dropdown-menu">
                    @foreach($menu['children'] as $child)
                        <a class="dropdown-item" href="{{$child['link']}}">{{$child['title']}}</a>
                    @endforeach
                </div>
            @endif
        </li>
    @endforeach
</ul>

使用此数组:

return[
    'horizontal' => [
        [
            'title' => 'Dashboard',
            'link'  => '/admin',
            'active' => 'admin',
            'icon'  => 'fa fa-dashboard',
        ],
        [
            'title' => 'Settings',
            'link'  => '/admin/settings',
            'active' => 'admin/settings*',
            'icon'  => 'fa fa-cogs',
        ],
        [
            'title' => 'Users',
            'link'  => '#',
            'active' => 'admin/users*',
            'icon'  => 'fa fa-user',
            'children' => [
                [
                    'title' => 'All Users',
                    'link'  => '/admin/users',
                    'active' => 'admin/users',
                ],
                [
                    'title' => 'User Profile',
                    'link'  => '/admin/users/1',
                    'active' => 'admin/users/*',
                ]
            ]
        ],
    ]
];

但是我收到了这个错误:

ErrorException in 23bb0e870ad0fbd7e21a6ce757b7bc9560d31591.php line 3:
Call to undefined function set_active() (View: C:\xampp\htdocs\myproject\resources\views\admin\layouts\partials\nav\menu-horizontal.blade.php)

我在从中复制它的应用程序中没有出现此错误。我检查了set_active()是否存在,并确实:

<?php

use App\Space\Settings\Setting;

function set_active($path, $active = 'active') {

    return call_user_func_array('Request::is', (array)$path) ? $active : '';

}...

它也正好在我的旧项目中。为什么不在这里工作?

1 个答案:

答案 0 :(得分:0)

清除viewcache并生成新密钥并重新运行您的计划。

并将755777提供给存储文件夹

命令是

php artisan view:clear
php artisan cache:clear
php artisan key:generate

同时运行

composer update