문제

I am currently running into a problem when trying to use a custom helper class in Laravel 4.
I've created a folder in app/libraries which has a custom class MenuComposer.

app/libraries/folder/MenuComposer.php

<?php
    namespace 'folder\MenuComposer'

    class MenuComposer {
      // Code here
    }

I've edited composer.json to autoload the app/libraries folder and ran the dump-autoload command in console.

composer.json

    "autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php",
        "app/libraries"
    ]
},

And finally I call the class like so:

View::composer('layouts.back', 'folder/MenuComposer');

Whatever I try, Laravel keeps returning the message Class 'MenuComposer' not found

Does anyone here know what the problem might be?

도움이 되었습니까?

해결책

Your namespace should be declared as the following rather than with quotes:

namespace folder\MenuComposer;

Composer dump-autoload then generates the following in your "/vendor/composer/autoload_classmap":

'folder\\MenuComposer\\MenuComposer' => $baseDir . '/app/libraries/folder/MenuComposer.php'

Which would indicate the class can be reached at:

folder/MenuComposer/MenuComposer

Hope this helps!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top