Image View Select to Change
Yii 1.1 or above - tested on Yii 1.1.11 and above
/config/main.php
'import'=>array( ... 'application.extensions.*', ... ),
$this->widget('ext.imageSelect.ImageSelect', array( 'path'=>'path/to/current/image', 'alt'=>'alt text', 'uploadUrl'=>'url that accepts the uploaded image and returns the new path', 'htmlOptions'=>array() ));
public function actionUpload(){ $file = CUploadedFile::getInstanceByName('file'); // Do your business ... save on file system for example, // and/or do some db operations for example $file->saveAs('images/'.$file->getName()); // return the new file path echo Yii::app()->baseUrl.'/images/'.$file->getName(); }
Total 6 comments
Here is an example
about the action, as mentioned above, you can catch the file and do anything with it
Can you please give an example of the 'url' portion. I have tried numerous ways and can't get it to work. How could I use a model behaivour to change the image. i.e.
Thank you for this awesome extension!
http://yii.nefya.com
BTW: I forgot to mention a sample upload action
public function actionUpload(){ $file = CUploadedFile::getInstanceByName('file'); $file->saveAs('images/'.$file->getName()); echo Yii::app()->baseUrl.'/images/'.$file->getName(); }it is simply the url that the widget will post the image file to it, then it will handle this file [may save it to a database or file system, or add it to a model], then it should return the new image's path
what is 'uploadUrl' means? is this an action that upload the image and save it then gives the returned path?
Leave a comment
Please login to leave your comment.