CakePhp常用配置

来源:互联网 发布:loop在c语言 编辑:程序博客网 时间:2024/06/10 11:33

路由配置

/Home/index 作为默认首页,配置一个新的模块 api

<?phpuse 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']);    }}
原创粉丝点击