Yii2 enablePrettyUrl失败,前端发布请求失败

时间:2016-10-28 16:24:29

标签: yii2

我试图制作 这个网址 http://localhost/advanced/frontend/web/index.php?r=test 成 https:// localhost / advanced / frontend / web / tests in yii2

也接收邮寄请求

这是我在common / config / main.php中的编码

 <?php
 return [
  'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
  'components' => [
  'cache' => [
      'class' => 'yii\caching\FileCache',
  ],

  'urlManager' => [

   ],
   'urlManagerFrontEnd' => [
          'enablePrettyUrl' => true,
          'rules' => [
              [
                  'class' => 'yii\rest\UrlRule',
                  'controller' => ['test'],
                  'only' => ['index', 'create'],
              ],
          ],
          'showScriptName' => false,
    ],

 ],
];

这在我的前端testController中

命名空间frontend \ controllers;

use Yii;
use yii\rest\ActiveController;
use common\models\Test;
use yii\data\ActiveDataProvider;
class TestController extends ActiveController {
    public $modelClass = 'common\models\Test';

    public function actions(){
        $actions = parent::actions();
        unset($actions['create']);
        return $actions;
    }

   public function actionCreate(){
       $model = new Test();
       $model->load(Yii::$app->request->post(),'');
       $model->save();
       return $model;
    }




}

我尝试时在帖子请求中遇到问题 Postman result jpg

所以我有2个问题,第一个是prettyUrl和post请求

如果你有解决方案请轻松一点,因为我只学习php yii2 html css等1个月

0 个答案:

没有答案