在yii框架中接收错误400

时间:2014-08-21 09:40:22

标签: php html yii

我所拥有的是一个html表单,我想将数据从它传递给控制器​​,在那里它执行快速计算,然后更新数据库。

我收到的是错误400,我不知道为什么请求无效,因为我的设置类似于我正在使用的其他页面工作正常。

以下是控制器和视图中的操作。

<?php
/* @var $this TokensController */
/* @var $model Tokens */

$this->breadcrumbs = array(
'Tokens' => array('index'),
$model->TokenID => 
'buy',
);
?>

<h1>Buy Tokens 
</h1>
<?php
 echo  'Your balance is ' .$model->TokenAmount;
 ?>

<FORM name ="form1" method ="post" action = "buy">

 <input type='radio' name='qty' value='10' />10
 <input type='radio' name='qty' value='25' />25
 <input type='radio' name='qty' value='50' />50

</FORM>

控制器操作

public function actionBuy($qty) {

    $_id = Yii::app()->user->getId();
    $model = Tokens::model()->findByAttributes(array('UserID' => $_id));
    if ($model === null)
        throw new CHttpException(404, "Keep calm! If you havent bought tokens before this is normal");


    $this->render('buy', array(
        'model' => $model,));

   $qty = $_POST['qty'];
   echo $qty;
   $newtkamount = ($_model->TokenAmount + $qty);
   echo $qty . $newtkamount . $_model->TokenAmount;
}

2 个答案:

答案 0 :(得分:0)

尝试从actionBuy参数

中删除$ qty

公共功能actionBuy()

或者您可以将其更改为

公共功能actionBuy($ qty = 0)

答案 1 :(得分:0)

因此,我发现有效的解决方案是将参数设置为$qty = 0。 使用isset确认它是一个发布请求