Cakephp组件错误

时间:2013-10-20 20:35:35

标签: php cakephp cakephp-2.0 components

我的应用中有这个组件:

class ImageComponent extends Component {


var $image;
var $image_type;

function __construct($filename = null){
    if(!empty($filename)){
        $this->load($filename);
    }
}

function load($filename) {
    $image_info = getimagesize($filename); //<<== LINE OF THE ERROR
    $this->image_type = $image_info[2];
    if( $this->image_type == IMAGETYPE_JPEG ) {
        $this->image = imagecreatefromjpeg($filename);
    } elseif( $this->image_type == IMAGETYPE_GIF ) {
        $this->image = imagecreatefromgif($filename);
    } elseif( $this->image_type == IMAGETYPE_PNG ) {
        $this->image = imagecreatefrompng($filename);
    } else {
        throw new Exception("The file you're trying to open is not supported");
    }

}
}

但是,当我加载组件时,我收到了这个错误:

 getimagesize() expects parameter 1 to be string, object given [APP/Controller/Component/ImageComponent.php, line 33]

由于

1 个答案:

答案 0 :(得分:0)

组件的构造函数要求第一个参数是ComponentCollection对象。在旁注 - 改变父类函数的param类型是代码气味