zoukankan      html  css  js  c++  java
  • Yii2 基于RESTful api 坑 访问会把控制器名称变为复数

    'urlManager' => [ 'class' => 'yiiwebUrlManager', 'enablePrettyUrl' => true, 'enableStrictParsing' => true, 'showScriptName' => false, 'rules' => [ '' => 'cms/index', ['class' => 'yii estUrlRule', 'controller' => 'customer/api',   'pluralize' => false, ], #  定义方法: public function actionSearch($name);   <name> 就是search方法传入的参数 'POST customer/api/search/<name>' => 'customer/api/search', //'POST customer' => 'customer/index/create', ], ],

    这个配置可以解决加上 'pluralize' => false

    <?php
    $params = array_merge(
        require(__DIR__ . '/../../common/config/params.php'),
        require(__DIR__ . '/../../common/config/params-local.php'),
        require(__DIR__ . '/params.php'),
        require(__DIR__ . '/params-local.php')
    );
    
    return [
        'id' => 'app-api',
        'basePath' => dirname(__DIR__),
        'bootstrap' => ['log'],
        'controllerNamespace' => 'apicontrollers',
        'modules' => [
            'v1' => [
                'class' => 'apimodulesv1Modules',
            ],
        ],
        'components' => [
            'request' => [
                'csrfParam' => '_csrf-api',
            ],
            'user' => [
                'identityClass' => 'commonmodelsUser',
                'enableAutoLogin' => true,
                'identityCookie' => ['name' => '_identity-api', 'httpOnly' => true],
            ],
            'session' => [
                // this is the name of the session cookie used for login on the frontend
                'name' => 'advanced-api',
            ],
            'log' => [
                'traceLevel' => YII_DEBUG ? 3 : 0,
                'targets' => [
                    [
                        'class' => 'yiilogFileTarget',
                        'levels' => ['error', 'warning'],
                    ],
                ],
            ],
            'errorHandler' => [
                'errorAction' => 'site/error',
            ],
            'urlManager' => [
                'enablePrettyUrl' => true,
                'enableStrictParsing' => true,
                'showScriptName' => false,
                'rules' => [
                    ['class' => 'yii
    estUrlRule', 'controller' => 'v1/user', 'pluralize' => false,],
                ],
            ],
        ],
        'params' => $params,
    ];
    

      

  • 相关阅读:
    dayⅦ:元组、字典的其他操作+集合类型
    dayⅥ:作业
    dayⅥ:字符串操作+列表操作
    dayⅣ:赋值运算+if判断
    dayⅣ:赋值运算+if判断作业
    dayⅢ、基本数据类型+运算符
    爬虫解析bs4
    爬虫请求库之requests库
    爬虫原理
    各主流Linux系统解决方案pip安装mysqlclient报错
  • 原文地址:https://www.cnblogs.com/xiezhi/p/6270086.html
Copyright © 2011-2022 走看看