我想将一个聊天机器人(BotMan version 2.0)集成到一个现有的OctoberCMS项目中,下面是我迄今为止所做的工作:
1-我使用以下命令将BotMan添加到projct中:
composer require botman/botman2-我在与plugin.php文件相同的目录中创建了一个routes.php文件。
<?php
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
//Route::match(['get', 'post'], '/botman', 'BotManController@handle');
//Route::get('/botman/tinker', 'October\Demo\BotManController@tinker');
// Create an instance
$botman = BotManFactory::create($config);
// Give the bot something to listen for.
$botman->hears('hello', function (BotMan $bot) {
$bot->reply('Hello yourself.');
});
// Start listening
$botman->listen();我的问题是:
1-我必须在其中添加BotManController.php文件 2-我试图将BotManController.php添加到与routes.php文件相同的目录中,但我得到了以下错误:
Class 'App\Http\Controllers\Controller' not found(这是因为这是一个OctoberCMS项目,而不是Laravel项目.我没有应用程序目录)
谁能给我提供一个解决方案,或以另一种方式将Botman集成到OctoberCMS中!
发布于 2018-11-24 16:56:41
首先,阅读https://luketowers.ca/blog/how-to-use-laravel-packages-in-october-cms-plugins/和https://octobercms.com/docs/plugin/composer。
其次,只要您了解PHP名称空间以及如何正确引用它,您就可以将BotManController文件放置在您想要的插件中的任何位置。我可能会建议将它放在插件文件夹下的/ Illuminate\Routing\Controller /目录中,然后将Illuminate\Routing\Controller引用更改为引用基类Illuminate\Routing\Controller。您也可以将它放在/ controllers /目录中,但是在OctoberCMS中通常是为后端控制器保留的,所以我不建议将两者混合使用。
https://stackoverflow.com/questions/53449075
复制相似问题