Laravel 4.2:将 PHP 文件(库)包含到控制器中

2022-01-08 00:00:00 php laravel laravel-4

我正在使用 Laravel 4.2 做一个项目,我需要在控制器中包含一个 PHP 文件(一个将 PDF 转换为文本的库),然后返回一个带有文本的变量,知道怎么做吗?

I'm doing a project using Laravel 4.2 where I need to include a PHP file (a library to transform a PDF into Text) into the controller, and then return a variable with the text, any idea how?

这是我的控制器:

public function transform() {
    include ('includes/vendor/autoload.php');
}

还有我的 /app/start/global.php 文件:

ClassLoader::addDirectories(array(
    app_path().'/commands',
    app_path().'/controllers',
    app_path().'/models',
    app_path().'/database/seeds',
    app_path().'/includes',

));

这是错误:

include(includes/vendor/autoload.php): failed to open stream: No such file or directory

推荐答案

我认为你是对的兄弟,但是,我找到了另一种方法,也许不是正确的方法,但它有效.

I think you're right bro, but, i find another way, maybe not the right way, but it works.

就是这样,我创建了一个名为 Includes 的新文件夹并将我的文件放在那里,然后在/app/start/global.php 中添加了这一行:

Is like this, I created a new folder called Includes and put my files in there, then in the /app/start/global.php i added this line:

require app_path().'/includes/vendor/autoload.php';

现在正在工作:D

相关文章