CakePhp常用配置

路由配置

/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']);
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值