Laravel 4: loading an old library: how?

最后都变了- 提交于 2019-12-04 22:16:28

问题


I have an old library (phpquery) that I'd like to include in my project. I've put it inside vendor, but it doesn't work, as it's not PSR-0 compliant. I don't want it to load for every request, so I didn't put the require inside bootstrap autoload.php.

I don't even know, how I can get the root of the app. Running path() gives me a URL, not what I'm after.

So how can I do that?


回答1:


You can create a libraries directory just like in laravel 3 and include it in your class loader. You can do this via composer or laravel.

//composer.json
"autoload": {
    "classmap": [
        "app/commands",
        "app/libraries",
        "app/database/migrations",
        "app/tests/TestCase.php",
    ]
},

//app/starts/global.php
ClassLoader::register(new ClassLoader(array(
    app_path().'/libraries',
)));

Autoloading via Laravel does not require you to run "composer dumpautoload" every time a class is created or removed.

UPDATE - L4 Beta 4

ClassLoader::addDirectories(array(
    app_path().'/libraries',
));


来源:https://stackoverflow.com/questions/14572354/laravel-4-loading-an-old-library-how

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!