Hey everybody, I have a problem with image update.
I have a model with image field. I show the image field in form
<?php echo CHtml::activeFileField($model, ‘image’); ?>
And I have rules for image field
array(‘image’, ‘file’, ‘on’ => ‘insert’),
array(‘image’, ‘file’, ‘on’ => ‘update’, allowEmpty’=>true),
And I assume if user do not update image, I want to leave saved in AR value. But when I do
$model->attributes=$_POST[‘DbShowplace’];
in $_POST[‘image’] I have empty value b/c of hidden yii field for file i.e.
<input id="ytDbShowplace_image" type="hidden" value="" name="DbShowplace[image]" />
and image
is safe attribute, so eventually I have $model->image = null
If I don’t use this rule
array(‘image’, ‘file’, ‘on’ => ‘update’, allowEmpty’=>true),
I’ll have an error
2010/08/17 23:10:38 [warning] [application] Failed to set unsafe attribute "image".
Any sugesstions ) ?