douzhi8488 2013-07-10 08:11
浏览 20

$ _POST无法在自定义网址中使用

I have used custom urls in my application. When i create message it redirect me to the create form but when i submit the form it redirects back to the same form again. There is a condition in the controller if the $_POST variable is set then save it else redirect to the form. I thought the $_POST variable is not setting but when i print it in the form it was printed there. So, if the $_POST variable is set then why the condition fails? Following is my custom urls. Before using custom urls it was working ok.

  '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>',
                ),
            ),

And this is my .htaccess file.

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>

Is there something wrong here..?

EDIT

Here is my controller code.

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,
        ));
    }
  • 写回答

1条回答 默认 最新

  • duanbichou4942 2013-07-10 12:56
    关注

    If the redirect isn't happening then $model->save() isn't completing successfully. You can use print_r($model->getErrors()); to see the validation errors.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看