我读过这本书" Yii",我无法理解如何查看控制器接收的全局_POST数组?
查看 _form.php这个
<div class="row">
<?php
echo $form->labelEx($model,'category_id');
echo CHtml::DropDownList('Page[category_id]','', Category::allCategory(),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('subcategory/dynamicSubCategories'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#Page_subcategory_id', //selector to update
// 'data'=>array('category_id'=>'js:this.value'),
//leave out the data key to pass all form values through
)));
echo $form->error($model,'category_id');
?>
</div>
<div class="row">
<?php
echo $form->labelEx($model,'subcategory_id');
echo CHtml::dropDownList('Page[subcategory_id]','', array());
echo $form->error($model,'subcategory_id');
?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
SubcategoryController.php
public function actionDynamicSubCategories() {
$data = Subcategory::model()->findAllByAttributes(array('category_id' => $_POST['category_id']));
$data = CHtml::listData($data, 'id', 'title');
foreach ($data as $value => $name) {
echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);
}
}
我对来自控制器echo CHtml::DropDownList('Page[category_id]','', Category::allCategory(), ...
的观看SubcategoryController.php
的价值感兴趣吗?
答案 0 :(得分:0)
在控制器的顶部,您只需输出$ _POST数组。
e.g。
print_r($_POST);
或
var_dump($_POST);
这应该显示任何帖子值。
答案 1 :(得分:0)
要在Yii中获取_POST变量,您可以使用var_dump(Yii::app()->request->post);
答案 2 :(得分:0)
在我的情况下,控制器传递了这个_POST (Page['category_id'])
。
我在控制器中使用:
$x = Yii::app()->request->getPost('Page');
$y = $x['category_id'];
$data = Subcategory::model()->findAllByAttributes(array('category_id' => (int)$y));
解决!