简体   繁体   中英

Laravel start function not calling from inside a namespace

So I'm writing a Laravel 4 app and I've setup namespaces. I'm just trying to write some systemwide functionality that I can execute from anywhere mainly to create menus/setup language/currencies etc.

I have directory to global called "library" which has currently a file called Menu.php inside it which looks as follows:

    <?php

namespace Library;

use AppName\Model\Menu as MenuModel;

class Menu {

    public static function BuildMenu($id = 1) {

        //retrieve menu
        $menu = MenuModel::GetMenu($id);

        //sort content for page
        $data = $menu->toArray();
        print_r($data);
    }

}

I am currently attempting to call the BuildMenu function in the filters.php file with the following:

App::before(function($request)
{
    //
    View::share('Menu', Library\Menu::BuildMenu());
});

I get a class 'Library\\Menu' not found error from laravel. I'm presuming this is something to do with my lack of knowledge of namespaces so any clarity would be appreciated.

Did you add your library path to composer.json ?

if not, just add it to autoload > classmap >> app/library

and run artisan dump-autoload

should be fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM