我想从$_POST中获取一个数据,表单上的字段被称为"parametero",并且它被保存在$_POST上['Aracterizacion'],我想获取这个"parametro"并将其保存为var上的字符串,如何获取这个数据?
$_POST['Caracterizacion']['parametro']
那么表单上的字段是parametero?我将假设以下HTML:
<input type="text" name="parametero" id="param_1"/>
在这种情况下,您将访问该字段的内容,如下所示:
$var = $_POST['parametero'];
这假设该输入元素所在的表单元素的方法属性设置为POST
如果我的假设不正确,请进一步详细说明,并至少提供你的html。
这是视图:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'caracterizacion-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'parametro'); ?>
<?php echo $form->textField($model,'parametro',array('size'=>60,'maxlength'=>256)); ?>
<?php echo $form->error($model,'parametro'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget();
?>
</div><!-- form -->
这是控制器的动作
public function actionCreate()
{
$model=new Caracterizacion;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Caracterizacion']))
{
$model->attributes=$_POST['Caracterizacion'];
if($model->save())
{
$variable="hola";
Caracterizacion::model()->columna($variable);
$this->redirect(array('view','id'=>$model->id));
}
if($model->save() == false)
var_dump($model->errors);
}
$this->render('create',array(
'model'=>$model,
));
}
你可以看到我制作了一个名为variable的var,内容为"hola",它被带到模型上制作的一个类中,目前它是有效的,但问题是,我想用$_POST上的一个元素来替换"hola"字符串,当我用$_POST['Characterizacion']替换它时,它会给我一个错误"数组到字符串的转换",所以我不知道该怎么办,这就是为什么我问如何从$post 中只获得1个元素