rohit
(Rohit N Sarpotdar)
March 9, 2010, 8:53am
1
Referring to How to upload file to database , I can upload a ‘IMAGE’ file to database.
But how to display it in CDetailView. It has formatter ‘image’ supported, but it requires url of the file!
And I will be having it in longblob converted to string( in php ) .
Is it possible ? or I will have to use normal html to render image?
bettor
(Live Webscore)
March 9, 2010, 12:21pm
2
Referring to How to upload file to database , I can upload a ‘IMAGE’ file to database.
But how to display it in CDetailView. It has formatter ‘image’ supported, but it requires url of the file!
And I will be having it in longblob converted to string( in php ) .
Is it possible ? or I will have to use normal html to render image?
It is possible. try ‘type’=>‘html’
rohit
(Rohit N Sarpotdar)
March 10, 2010, 4:32am
3
html: the attribute value will be purified and then returned. (CFormatter)
This isn’t my solution! Well, I figured out the solution.
I created a controller action which on giving id, displays image from database. Now just have to give url i guess to CDetailView!
Rohit, would you mind posting some simple samples of your solution. I am facing this exact same issue.
rohit
(Rohit N Sarpotdar)
March 12, 2010, 4:06am
5
Here it goes
PropertyImageController has action view, in which i render a view which has,
<?php
header("Content-type: ".$model->image_type);
echo $model->image_data;
in a views/propertyImage/view.php
in a controller i change property_image_id to url
$model->property_image_id=Yii::app()->urlManager->createUrl(
'propertyImage/view',
array(
'id'=>$model->property_image_id
)
);
and now its just a matter of giving a url to CDetailView
array(
'label'=>'Property Image',
'name'=>'property_image_id',
'type'=>'image',
),
as there is no field in my property model which holds url, it holds id of property Image. So, I had to use the same variable to show image
Hope this helps. and if you can make it more simple, please go ahead and suggest…
Thanks for showing this, great place for me to start. -later
rohit:
Here it goes
PropertyImageController has action view, in which i render a view which has,
<?php
header("Content-type: ".$model->image_type);
echo $model->image_data;
in a views/propertyImage/view.php
in a controller i change property_image_id to url
$model->property_image_id=Yii::app()->urlManager->createUrl(
'propertyImage/view',
array(
'id'=>$model->property_image_id
)
);
and now its just a matter of giving a url to CDetailView
array(
'label'=>'Property Image',
'name'=>'property_image_id',
'type'=>'image',
),
as there is no field in my property model which holds url, it holds id of property Image. So, I had to use the same variable to show image
Hope this helps. and if you can make it more simple, please go ahead and suggest…
don.vijay05
(don.vijay05@gmail.com)
June 11, 2014, 5:20am
8
hi rohit…
am very new to yii… am also facing this problem. now i need a solution. On controller were we use this code… plz help me out.
in a controller i change property_image_id to url
$model->property_image_id=Yii::app()->urlManager->createUrl(
'propertyImage/view',
array(
'id'=>$model->property_image_id
)
);
ahmed201
(Rifajas)
June 11, 2014, 5:27am
9
Hello rohit.
saving image into database is not a good idea at all. though this feature was supported it will affect your database performance instead of saving the image directly into the database you can save the image into the file system and store the image name to the db. this will highly reduce you database performance issue.
Referring to How to upload file to database , I can upload a ‘IMAGE’ file to database.
But how to display it in CDetailView. It has formatter ‘image’ supported, but it requires url of the file!
And I will be having it in longblob converted to string( in php ) .
Is it possible ? or I will have to use normal html to render image?