images

Display the image on view file
3 followers

Hi Friends,

This is my first Extension created how to display image on view file using extension

First you can create the function folder in protected/extersions/functions and also create the images folder on your root directory

In Functions folder** created the Functions.php** and write a code

<?php
class Functions extends CApplicationComponent {
 
 
    public function returnSomething($filePath,$image){
 
        $path=Yii::app()->getBaseUrl(true);
        $folder=$path. $filePath.'/images/'.$image;
        if ($image!='' && file_exists(YiiBase::getPathOfAlias('webroot') . $filePath)) {
            $filePath= "<img src='".$folder."'>";
        } else {
             $filePath="<img height='150px' width='150px' src='http://www.pa-legion.com/wp-content/themes/streamline_20/images/NoPhotoAvailable.jpg'>";
 
        }
        return $filePath;
 
    }
}
?>

Finally install this extension in config/main.php

'components'=>array(
          'functions'=>array(
                        'class'=>'application.extensions.functions.Functions',
                ),
 ),

and use this extension using this line

print Yii::app()->functions->returnSomething($filePath='',$image);

in $image is your data image so u can fetch image in $image varibale

for example..

//Yii::app()->phpThumb->create('../images/myImage.jpg');
$vendor=VenueGalllery::model()->find('id=14');
$image= $vendor->image_name;
print Yii::app()->functions->returnSomething($filePath='',$image);

Total 3 comments

#16284 report it
sefburhan at 2014/02/06 05:51am
Good for beginners !

Welcome and yes we are here to appreciated our work, too cool but one suggestion if not minding ! i think if it was in how-to/tutorial category of wiki as article b/c here you are just explaining how things works.

#15226 report it
Nisanth thulasi at 2013/10/19 08:54am
yes its nice

yes trond am also supporting you. This is simple and usefull

#13895 report it
trond at 2013/07/04 12:20pm
Thanks for sharing

I'm not sure why this was voted down by someone. I found it an interesting read.

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet