【问题标题】:CakePHP - Loading routes files from a pluginCakePHP - 从插件加载路由文件
【发布时间】:2012-08-23 06:47:50
【问题描述】:

有人能指点我这是怎么做到的吗?我想在插件文件夹本身的配置文件中定义插件特定的路由。

目前我只是在我的主 routes.php 文件中定义插件的路由。这显然会变得很长。所以我想将它重构为一个单独的配置文件并将其放在插件的文件夹中。

但我看到有一个代码实际上会自动加载特定于插件的路由,但我找不到任何关于此的文档。 在“config/routes.php”中有一行写着

/**
 * Load all plugin routes.  See the CakePlugin documentation on 
 * how to customize the loading of plugin routes.
 */
CakePlugin::routes();

通过插件路由搜索here 是完全不同的主题。而plugin documentation 对此只字未提。

【问题讨论】:

    标签: php cakephp plugins routing routes


    【解决方案1】:

    查看本节中的文档:Plugin Configuration

    首先,add your routes 到 app/Plugin/YourPlugin/Config/routes.php

    并在 app/Config/bootstrap.php 中执行此操作:

    <?php
    CakePlugin::loadAll(array(
        'Blog' => array('routes' => true),
        'ContactManager' => array('bootstrap' => true),
        'WebmasterTools' => array('bootstrap' => true, 'routes' => true),
    ));
    

    它会加载您所有可用的插件,但会添加您在数组参数中列出的附加功能。如果您想为所有可用插件加载路由,请在 app/Config/bootstrap.php 中执行此操作:

    <?php
    CakePlugin::loadAll(array(
        array('bootstrap' => true)
    ));
    

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2014-09-08
      • 1970-01-01
      • 2012-04-09
      • 2012-12-03
      • 2016-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多