I am using CakePHP framework version 2.6.1
.
I am creating a function which will get properties images and will create its thumbnail by phpThumb
.
My issue is I am not able to create thumbnail from phpThumb
in my function. I am getting all the data as I want. Here is my controller
I tried to load helper of phpThumb
like this
public $helpers = array('PhpThumb.PhpThumb');
but didn't work for me. Then I tried to import it from my parent AppController like
App::import('Helper', 'PhpThumb.PhpThumb');` but unfortunately it didn't work too.
I checked my error logs
and found this error
PHP Fatal error: Call to a member function url() on a non-object in /home/gulfsothebysrealty/public_html/app/Controller/CronController.php on line 39
in $propertyImages['Photo']['image_url']
i am getting propspace server image url
How can I generate a thumbnail by using phpThumb
in controller?
class CronController extends AppController {
public function index() {
$properties = $this->Property->find( 'all', array(
'conditions' => array(
'Property.thumb_updated' => 0
),
'limit' => 5,
'order' => array( 'Property.id' => 'desc' )
)
);
foreach ( $properties as $property ) {
$propertyId = $property['Property']['id'];
$data = array( 'id' => $propertyId, 'thumb_updated' => 1 );
$this->Property->save( $data );
$getImages = $this->Property->Photo->find( 'all', array(
'conditions' => array(
'Photo.property_id' => $propertyId,
),
'order' => array( 'Photo.property_id' => 'desc' )
) );
foreach ( $getImages as $propertyImages ) {
if ( ! empty( $propertyImages['Photo']['image_url'] ) ) {
/*line 39*/ $propertyImageThumb = $this->PhpThumb->url( $propertyImages['Photo']['image_url'], array(
'w' => 1349,
'h' => 500,
'zc' => 1
) );
echo '<pre>';
print_r( $propertyImageThumb );
echo '</pre>';
}
}
}
}
}
I got the solution guys,
I was doing a single mistake
i need to import phpThumb helper
from AppController
as i did
App::import( 'Helper', 'PhpThumb.PhpThumb' );
then i had to make an object
for phpThumb Helper
$phpthumb = new PhpThumbHelper(new View());
After this now i am able to create thumbnail by using $phpThumb
$propertyImageThumb = $phpThumb->url( $propertyImages['Photo']['image_url'], array(
'w' => 1349,
'h' => 500,
'zc' => 1
) );