如何从cakephp 3中的url调用插件控制器

时间:2017-11-11 17:54:53

标签: cakephp cakephp-3.0

我有一个名为PanelAdmin的管理面板插件。 这是CategoriesController.php

<?php

namespace PanelAdmin\Controller;

use Cake\Controller\Controller;
use Cake\ORM\TableRegistry;

class CategoriesController extends AppController
{
public function initialize()

    {

        parent::initialize();

        $this->loadComponent('Flash'); // Include the FlashComponent

    }

public function index()

    {

        $this->set('topics', $this->categories->find('all'));

    }

    }

?>

这是Template / Topics / index.ctp

中的主题视图
<h1>Blog topics</h1>

<p><?= $this->Html->link('Add Topic', ['action' => 'add']) ?></p>

<table>

    <tr>

        <th>Id</th>

        <th>Title</th>

        <th>Created</th>

        <th>Actions</th>

    </tr>

我想直接调用PanelAdmin,它应该显示上面的视图但是现在我得到了以下错误:

Error: CategoriesController could not be found.

它在主src文件夹中搜索我希望它在我点击http://localhost/multi_shopping/PanelAdmin此网址时搜索到插件文件夹。

2 个答案:

答案 0 :(得分:0)

您需要添加连接到/ PanelAdmin的路线

$routes->connect('/PanelAdmin', [
    'plugin' => 'PanelAdmin', 
    'controller' => 'Categories', 
    'action' => 'index'
]);

答案 1 :(得分:0)

首先确保您的插件已加载https://book.cakephp.org/3.0/en/plugins.html#plugin-configuration

您不需要在插件中定义路线以访问网址中的插件控制器,cakephp默认路由会自动使您的控制器可以作为 / panel-admin / categories