Yii2高级,无法验证您的数据提交错误

时间:2018-05-15 05:43:10

标签: php yii2 yii2-advanced-app

我正在使用yii2高级模板来构建网站。 当我想使用表单创建一个新的行时,它可以工作,但在第二次提交或更新几秒后,我收到此错误。 我在这里阅读了许多答案,但我不想禁用crf令牌和aleardy我有

<head/>

在我的布局use \yii\web\Request; $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') ); // Replace url $request = new Request(); $baseUrlFront = str_replace('/backend/web', '/frontend/web', $request->getBaseUrl()); $scriptUrlFront = str_replace('/backend/web', '/frontend/web', $request->getScriptUrl()); return [ 'id' => 'app-backend', 'basePath' => dirname(__DIR__), 'controllerNamespace' => 'backend\controllers', 'bootstrap' => ['log'], 'modules' => [], 'components' => [ 'user' => [ 'identityClass' => 'common\models\User', 'enableAutoLogin' => true, 'identityCookie' => [ 'name' => '_backendUser', // unique for backend 'path'=>'/backend/web' , // correct path for the backend app. ] ], 'session' => [ 'name' => 'regergwer2343423f238h923f9h9234', // unique for backend 'savePath' => __DIR__ . '/../runtime', // a temporary folder on backend ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], 'errorHandler' => [ 'errorAction' => 'site/error', ], 'i18n' => [ 'translations' => [ 'writesdown' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@app/messages', // if advanced application, set @frontend/messages 'sourceLanguage' => 'en', 'fileMap' => [ //'main' => 'main.php', ], ], ], ], 'urlManagerFront' => [ 'class' => 'yii\web\urlManager', 'scriptUrl' => $scriptUrlFront, 'baseUrl' => $baseUrlFront, ], 'urlManagerBack' => [ 'class' => 'yii\web\urlManager', ], 'authManager' => [ 'class' => 'yii\rbac\DbManager', ], ], 'params' => $params, ];

任何建议!?。

配置文件:

<?php $this->beginPage() ?>
    <!DOCTYPE html>
    <html lang="<?= Yii::$app->language ?>">
    <head>
        <meta charset="<?= Yii::$app->charset ?>">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noindex, nofollow">
        <?= Html::csrfMetaTags() ?>

        <title>WritesDown &raquo; <?= Html::encode($this->title) ?></title>
        <?php $this->head() ?>
    </head>
    <body
        class="<?= isset(Yii::$app->params['bodyClass']) ? Yii::$app->params['bodyClass'] : "skin-blue sidebar-mini"; ?>">
    <?php $this->beginBody() ?>
    <?= $content; ?>
    <?php $this->endBody() ?>
    </body>
    </html>
<?php $this->endPage() ?>

布局:

FieldValue.serverTimestamp()

1 个答案:

答案 0 :(得分:-1)

  1. 可以是一个解决方案,但仅在特殊情况下推荐!!!
  2. 禁用csrf检查一个控制器的所有操作

    Add the follow code to controller part:
       public $enableCsrfValidation = false;
    
    1. 使用此:

      public function beforeAction($ action) {    $ this-&gt; enableCsrfValidation = false;    return parent :: beforeAction($ action); }