I am pretty new with MVC and Yii framework, therefore there is a good chance that my question is pretty stupid. If so, accept my appologies in advance.
I want to have a form in my admin section of the website, where, user can post some content. I followed the tutorial for sample blog however it seems that the content added to the fields that are defined as text in the database (textarea in my form) don’t get updated after submitting the form (everything else works fine). here is the sql statement for my table:
CREATE TABLE `tbl_show` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`presentation` text,
PRIMARY KEY (`id`),
KEY `fk_tbl_show_tbl_season1` (`tbl_season_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
I used Gii to make my Model and CRUD, I only add here the parts that might be related:
On my controller:
public function actionCreate()
{
$model=new Show;
if(isset($_POST['Show']))
{
$model->attributes=$_POST['Show'];
if($model->save())
{
$this->redirect(array('view','id'=>$model->id));
}
}
$this->render('create',array(
'model'=>$model,
));
and my _form.php:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'show-form',
'enableAjaxValidation'=>false,
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'presentation'); ?>
<?php echo $form->textArea($model,'presentation',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'presentation'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Model Rules:
return array(
array('id, presentation', 'safe', 'on'=>'search'),
);
I don’t get why only the text content don’t get updated, they appear as null in the database.
Thank you in advance,
Cheers,
Mahsa
You have to make the attribute safe . Add this to your
Showmodels validation rules