Laravel 5:找不到库类 [英] Laravel 5: Library class not found
问题描述
我已经从github安装了这个库:
I've installed this library from github:
https://github.com/robholmes/term-extractor
我将文件放在public/term-extractor
下.
我尝试创建一条路径来测试库的结果,但始终出现错误Class 'TermExtractor' not found
.
I tried creating a route to test the results of the library, but I keep getting the error Class 'TermExtractor' not found
.
这是路线:
Route::get('/test', function()
{
require public_path() . '/term-extractor/src/TermExtractor/TermExtractor.php';
$text = 'Inevitably, then, corporations do not restrict themselves merely to the arena of economics. Rather, as John Dewey observed, "politics is the shadow cast on society by big business". Over decades, corporations have worked together to ensure that the choices offered by \'representative democracy\' all represent their greed for maximised profits. This is a sensitive task. We do not live in a totalitarian society - the public potentially has enormous power to interfere. The goal, then, is to persuade the public that corporate-sponsored political choice is meaningful, that it makes a difference. The task of politicians at all points of the supposed \'spectrum\' is to appear passionately principled while participating in what is essentially a charade.';
$extractor = new TermExtractor();
$terms = $extractor->extract($text);
// We're outputting results in plain text...
header('Content-Type: text/plain; charset=UTF-8');
// Loop through extracted terms and print each term on a new line
foreach ($terms as $term_info) {
// index 0: term
// index 1: number of occurrences in text
// index 2: word count
list($term, $occurrence, $word_count) = $term_info;
echo "$term\n";
}
});
怎么了?
推荐答案
首先,您应该为此TermExtractor
"require": {
"robholmes/term-extractor" : "3.*"
}
内部文件app.php
中,您需要做2件事(类似这样,不知道别名和提供者的正确名称(一定要在执行composer update
之前先做)
Inside file app.php
you need to do 2 things (something like this, dunno the proper name of alias and provider (be sure to do composer update
before doing it)
首先添加提供商
'providers' => [
term-extractor/TermExtractorProvider::class
]
第二个添加别名
'aliases' => [
'TermExtractor' => term-extractor\TermExtractor\Facades\TermExtractor::class,
]
这应该为您提供别名TermExtractor
,您可以在整个应用程序中使用该别名,而无需每次执行require public_path() . '/term-extractor/src/TermExtractor/TermExtractor.php';
That should give you alias TermExtractor
which u can use in whole app without each time do require public_path() . '/term-extractor/src/TermExtractor/TermExtractor.php';
希望有帮助
这篇关于Laravel 5:找不到库类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!