Monday, 16 February 2015

Display the URLs of Image in the CgridView of YII

Here the application name is dev_tslr where the images are residing outside of the application names tslrimgs

for example in the same D: the both directories dev_tslr and tslrimgs are existing

so the url Yii::app()->baseUrl gives us the path of dev_tslr since the tslrimgs are outside of this folder
../ is appended so we move back to home folder i.e., outside of application folder and then we are choosing the tslrimgs

if the uploads folder existing in the application itself then we can directly use the path

Yii::app()->baseUrl.'/uploads/' can be used

Yii::app()->basePath -- gives the app_dir/protected path.


<?php
// Dialog::message('LOGIN SUCCESS', "Welcome $uname");
$uname=Yii::app()->user->name;
if($uname=='admin') {
 $format='{view}{update}{delete}';
 }
 else{
  $format='{view}{update}';
 }
?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'tslrimg-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'id',
        'ward',
        'block',
//     'image',
        array(   
            'header' => 'Image',
            'name' => 'image',
            'value' => 'CHtml::link($data->image,Yii::app()->baseUrl."/../tslrimgs/".$data->image,array("target"=>"_blank"))',
            'type'=>'raw',
        ),

        'mand_name',
        'vill_name',
        'tsnofrom',
        'tsnoto',
        array(
            'class'=>'CButtonColumn',
            'template'=>$format,
        ),
    ),
)); ?>

No comments:

Post a Comment