Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>_form code for file upload field : </p> <pre><code>&lt;?php $form=$this-&gt;beginWidget('CActiveForm', array( 'id'=&gt;'post-form', 'enableAjaxValidation'=&gt;false, 'htmlOptions' =&gt; array('enctype' =&gt; 'multipart/form-data'), )); ?&gt; &lt;div class="row"&gt; &lt;?php echo $form-&gt;labelEx($model, 'image');?&gt; &lt;?php echo $form-&gt;fileField($model, 'image'); ?&gt; &lt;?php echo $form-&gt;error($model, 'image'); ?&gt; &lt;/div&gt; &lt;?php $this-&gt;endWidget(); ?&gt; </code></pre> <p>Controller Code:</p> <pre><code>public function actionCreate() { $model=new Post; if(isset($_POST['Post'])) { $model-&gt;attributes=$_POST['Post']; $uploadedFile=CUploadedFile::getInstance($model,'image'); $fileName = $uploadedFile; $model-&gt;image = $fileName; if($model-&gt;save()){ $uploadedFile-&gt;saveAs('C:/Program Files/Apache Group/Apache2/htdocs'.Yii::app()-&gt;baseUrl.'/images/thumbnails/'.$fileName); $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id)); } } $this-&gt;render('create',array( 'model'=&gt;$model, )); } </code></pre> <p>diplay view code :</p> <pre><code>&lt;?php $this-&gt;widget('zii.widgets.grid.CGridView', array( 'dataProvider'=&gt;$model-&gt;search(), 'ajaxUpdate' =&gt; false, 'columns'=&gt;array( array( 'name'=&gt;'Thumbnail', 'value'=&gt;array($model,'showThumbnail'), // function in model 'type'=&gt;'html', 'htmlOptions'=&gt;array('class'=&gt;'thumbnail'), ), ) )); ?&gt; </code></pre> <p>model code :</p> <pre><code>place this function in ur model : public function showThumbnail($data){ $path = $data-&gt;image; return CHtml::image(Yii::app()-&gt;baseUrl.'/images/thumbnails/'.$path); // same path as ur uploaded file path } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload