Yii2 enablePrettyUrl失败和前端post请求失败
我在试着做些什么 此url 进入 htttp://localhost/advanced/frontend/web/tests 在yii2中 也可以接收post请求 这是我在common/config/main.php中编写的代码Yii2 enablePrettyUrl失败和前端post请求失败,yii2,Yii2,我在试着做些什么 此url 进入 htttp://localhost/advanced/frontend/web/tests 在yii2中 也可以接收post请求 这是我在common/config/main.php中编写的代码 <?php return [ 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 'components' => [ 'cache' => [ 'class'
<?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,
],
],
];
当我尝试时,我在post请求中遇到了问题
所以我有两个问题,第一个是prettyUrl和post请求
如果你有一个解决方案,请让它变得简单,因为我刚刚学习了一个月的php yii2 html css等只是为了确定:你有相应的
.htaccess
-文件吗?这表明到现有文件和文件夹的url不受yii2的url管理器的影响,并保持直接访问。请确定:您是否有相应的.htaccess
-文件?这表明到现有文件和文件夹的url不受yii2的url管理器的影响,并保持直接访问。
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;
}
}