[EXTENSION] Ajax CRUD gii Template

God bless you my friend…i was trying for days to find what the problem was!!

Thank you again!!

Hello guys!!

I’ll get into the point directly. I have an image field on a database’s table where i want to store an image. While googling around i figured out that the best way to do that is to store the image on the server’s file system and keep the internal path of the image to the appropriate field.

So i’ve added to the _ajax_form.php the following lines of code:


<div class="row">        

<?php echo $form->labelEx($model,'Infrastructure_Photo'); ?>        

<?php echo CHtml::activeFileField($model, 'Infrastructure_Photo');         

<span id="success-Infrastructures_Infrastructure_Photo" class="hid input-notification-success  success png_bg right"></span>        

<div>  

<small></small>        

</div>        

 <?php echo $form->error($model,'Infrastructure_Photo'); ?>     

</div>

and in the controller and particularly in the actionAjax_Create() method the following:




$uploadedFile=CUploadedFile::getInstance($model,'Infrastructure_Photo');  

$fileName = "{$model->id}"; // I want to change the image's filename to something more meaningful to me like (so as not to have overwriting images) that is the record id.

$model->Infrastructure_Photo = $fileName; 

$uploadedFile->saveAs(Yii::app()->basePath.'/../images/'.$fileName);

The problem is that when using the $fileName = “{$model->id}”; or the $fileName = “{$this->id}”; can’t make it work properly. In fact nothing is saved unless i change the command to $fileName = “whateveriwant”; Obviously the file is saved named as whateveriwant.jpg but that’s for once.

The point is that i want to rename the image every time so it fits with the record id of a particular record.

Has anybody tried to do something similar to this??

Custom Validation rules and validation like 'unique’are not working . What to do?