我正在学习cakephp 3框架。更好的说法我对此非常陌生。
我正在尝试制作一个插件。
我发了这样一个插件bin/cake bake plugin myFirstPlugin
然后我使用
bin/cake bake controller --plugin myFirstPlugin test
因此,在我的插件控制器中,我定义了一个除了输出消息之外什么都不做的功能。
这是我的插件的控制器
<?php
namespace myFirstPlugin\Controller;
use myFirstPlugin\Controller\AppController;
class testController extends AppController
{
public function index()
{
$msg = 'test';
$this->set(compact('msg'));
$this->set('_serialize', ['msg']);
}
}
?>
并且在我的应用程序的路径中(不是在插件的路径中)我写了这个:
Router::scope('/myFirstPlugin/index', function (RouteBuilder $routes){
$routes->connect('/', ['controller' => 'test', 'action' => 'index']);
});
所以,当我尝试使用以下网址
来调用它时http://localhost/myApplication/myFirstPlugin/index
我收到了这个错误:
Error: testController could not be found.
Error: Create the class testController below in file: src\Controller\testController.php
即使我创建了一个控制器,为什么会出现这样的错误。谢谢!
答案 0 :(得分:1)
您需要在$routes->connect
Router::scope('/myFirstPlugin/index', function (RouteBuilder $routes){
$routes->connect('/', ['plugin' => 'myFirstPlugin','controller' => 'test', 'action' => 'index']);
});