找不到cakephp3-控制器

时间:2017-03-30 10:02:03

标签: php cakephp-3.0

我正在学习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

即使我创建了一个控制器,为什么会出现这样的错误。谢谢!

1 个答案:

答案 0 :(得分:1)

您需要在$routes->connect

中提及您的插件名称
Router::scope('/myFirstPlugin/index', function (RouteBuilder $routes){  
    $routes->connect('/', ['plugin' => 'myFirstPlugin','controller' => 'test', 'action' => 'index']);
}); 
相关问题