0

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.

3
  • why are you using a framework in language that you do not understand ? Commented Oct 7, 2013 at 16:41
  • ...I understand PHP I just haven't used namespaces before as I have been working on legacy apps. Please dont comment if you arent going to be helpful Commented Oct 7, 2013 at 16:45
  • This could be helpful too. Commented Oct 7, 2013 at 17:42

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I added it to global.php as: app_path().'/library' instead. This should perform the same I believe?
as it mention in the source "In addition to using Composer, you may use the Laravel class loader to load your controllers and models ..."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.