Laravel 4:加载旧库:如何? [英] Laravel 4: loading an old library: how?
问题描述
我有一个旧的库( phpquery ),我想将其包含在我的项目中.我已将其放入供应商内部,但由于它不符合PSR-0标准,因此无法正常工作.我不想为每个请求都加载它,所以我没有将require
放在bootstrap autoload.php中.
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.
我什至不知道如何获得该应用程序的根目录.运行path()
会给我一个URL,而不是我想要的.
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.
那我该怎么办?
推荐答案
您可以像在laravel 3中一样创建一个库目录,并将其包含在类加载器中.您可以通过作曲家或laravel完成此操作.
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',
)));
通过Laravel自动加载不需要每次创建或删除类时都运行"composer dumpautoload".
Autoloading via Laravel does not require you to run "composer dumpautoload" every time a class is created or removed.
更新-L4 Beta 4
UPDATE - L4 Beta 4
ClassLoader::addDirectories(array(
app_path().'/libraries',
));
这篇关于Laravel 4:加载旧库:如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!