my DB have a field “repayment_date”,it’s timestamp.
i want to PSOT a value "RepaymentDateText" to set the "repayment_date". the value is like this: 2013 -04-27
the getter part is OK
public function getRepaymentDateText()
{
if (empty($this->repayment_date)) {
return null;
} else {
return date('Y-m-d',$this->repayment_date);
}
}
setter part is written like this
public function setRepaymentDateText($value)
{
if(empty($value) || !$value) return false;
$this->repayment_date = strtotime($value.' 00:00:00');
}
The GII default in Controller using $ Model-> attributes = $ _POST [’***’] This automatic filtering the POST over RepaymentDateText the value.
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Blacklist']))
{
$model->attributes=$_POST['Blacklist'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('update',array(
'model'=>$model,
));
}
I can activate setRepaymentDateText in the model beforeSave use the following code, but this writing is not very appropriate.
$this->RepaymentDateText = $_POST['Blacklist']['RepaymentDateText'];
The first question: How to write better?
The second problem: $ _POST [‘blacklist’] [‘RepaymentDateText’] This value should be how to verify before more complex yii specification? Written in the rules ()? Please give me a sample code , thank you.