路由配置
将 /Home/index
作为默认首页,配置一个新的模块 api
<?php
use Cake\Core\Plugin;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
use Cake\Routing\Route\DashedRoute;
Router::defaultRouteClass(DashedRoute::class);
Router::prefix('api', function ($routes) {
$routes->connect('/', ['controller' => 'Home', 'action' => 'index']);
$routes->extensions(['json']);
$routes->fallbacks('DashedRoute');
});
Router::scope('/', function (RouteBuilder $routes) {
$routes->connect('/', ['controller' => 'Home', 'action' => 'index']);
$routes->extensions(['json']);
$routes->fallbacks(DashedRoute::class);
});
Plugin::routes();
添加公共函数文件 functions.php
在 config
目录下添加 functions.php
文件,在 path.php
文件中添加以下代码:
require __DIR__ . '/functions.php';
引入bootstrap.UI 插件
在 config/bootstrap.php
文件中添加以下代码:
Plugin::load('BootstrapUI');
添加助手函数
在 /src/view/AppView.php
文件中写入:
class AppView extends View
{
/**
* Initialization hook method.
*
* Use this method to add common initialization code like loading helpers.
*
* e.g. `$this->loadHelper('Html');`
*
* @return void
*/
public function initialize()
{
$this->loadHelper('Html', ['className' => 'BootstrapUI.Html']);
$this->loadHelper('Form', ['className' => 'BootstrapUI.Form']);
$this->loadHelper('Flash', ['className' => 'BootstrapUI.Flash']);
$this->loadHelper('Paginator', ['className' => 'BootstrapUI.Paginator']);
}
}