0

アプリケーションでカスタム URL を使用しました。メッセージを作成すると作成フォームにリダイレクトされますが、フォームを送信すると同じフォームに再度リダイレクトされます。$_POST 変数が設定されている場合はコントローラーに条件があり、保存しない場合はフォームにリダイレクトされます。$_POST 変数が設定されていないと思いましたが、フォームに印刷するとそこに印刷されました。では、$_POST 変数が設定されている場合、なぜ条件が失敗するのでしょうか? 以下は私のカスタムURLです。カスタム URL を使用する前は、問題なく動作していました。

  'urlManager' => array(
                'urlFormat' => 'path',
                'showScriptName' => false,
                'rules' => array(
                    '' => 'questions/index',
                    'messages' => 'messages/index',
                    'tags' => 'tags/index',
                    'login' => 'site/login',
                    'signup' => 'users/create',
                    '<id:\w+>' => 'users/view',
                    '<controller:\w+>/<id:\d+>' => '<controller>/view',
                    '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                    '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
                    'gii' => 'gii',
                    'gii/<controller:\w+>' => 'gii/<controller>',
                    'gii/<controller:\w+>/<action:\w+>' => 'gii/<controller>/<action>',
                ),
            ),

これが私の .htaccess ファイルです。

Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>

ここで何か問題がありますか..?

編集

これが私のコントローラーコードです。

public function actionUpdate($id) {
        $model = $this->loadModel($id);

        if (isset($_POST['User'])) {
            $model->attributes = $_POST['User'];
            if ($model->save())
                $this->redirect(array('view', 'id' => $model->id));
        }

        $this->render('update_info', array(
            'model' => $model,
        ));
    }
4

1 に答える 1

0

リダイレクトが発生していない場合は、$model->save()正常に完了していません。print_r($model->getErrors());検証エラーを確認するために使用できます。

于 2013-07-10T12:56:36.927 に答える