【发布时间】:2017-01-23 13:59:46
【问题描述】:
我使用的是 CakePHP 框架版本2.6.1。
我正在创建一个函数,它将获取属性图像并通过phpThumb 创建其缩略图。
我的问题是我无法在我的函数中从 phpThumb 创建缩略图。我正在获取我想要的所有数据。这是我的控制器
我试图像这样加载phpThumb 的助手
public $helpers = array('PhpThumb.PhpThumb');
但对我不起作用。然后我尝试从我的父母AppController likeApp::import('Helper', 'PhpThumb.PhpThumb');` 导入它,但不幸的是它也没有用。
我检查了我的error logs,发现了这个错误
PHP 致命错误:在第 39 行的 /home/gulfsothebysrealty/public_html/app/Controller/CronController.php 中的非对象上调用成员函数 url()
在$propertyImages['Photo']['image_url'] 我正在获取propspace 服务器图片网址
如何在控制器中使用phpThumb 生成缩略图?
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>';
}
}
}
}
}
【问题讨论】:
-
phpthumb 是一个古老而可怕的库。试试想象一下,我在它周围写了一个蛋糕插件包装器github.com/burzum/cakephp-imagine-plugin 另外,控制器是进行数据操作的错误位置。
-
问题是我在一个 cakephp 版本为 2.6 的网站上工作,我必须使用 phpthumb 我会在任何新网站上尝试你的插件。
-
@OwaisAslam - 请选择 2.x 分支在 cakephp 2 上实现
-
2.x 分支 ?? @justrohu