【问题标题】:PHP error when loading library in Codeiginiter在 Codeigniter 中加载库时出现 PHP 错误
【发布时间】:2016-10-05 05:19:34
【问题描述】:

我已将 ColorsOfImage PHP class from humanmade 作为新库包含在我的 Codeigniter 中。

现在当我在控制器中加载库时,我可以毫无问题地使用该类的功能,但是在加载库时总是出现以下错误,即__construct中的$image函数为空!?

这里是类的__construct函数:

public function __construct( $image, $precision = 10, $maxnumcolors = 5, $trueper = true ) {
        $this->image = $image;
        $this->maxnumcolors = $maxnumcolors;
        $this->trueper = $trueper;
        $this->getImageSize();
        $this->precision = $precision;
        $this->readPixels();
        $this->_excluded_colors[] = $this->getBackgroundColor();
    }

【问题讨论】:

    标签: php codeigniter class


    【解决方案1】:

    你应该检查docs说的是哪里:

    library($library[, $params = NULL[, $object_name = NULL]])
    

    参数:

    • $library(混合)- 库名称为字符串或具有多个库的数组
    • $params (array) – 传递给加载库的构造函数的可选参数数组
    • $object_name (string) – 分配库的可选对象名称

    如果 CI 使用带有来自控制器的构造函数参数的自定义库:

    $this->load->library('colorsofimage', [$image, $precision = 10, $maxnumcolors = 5, $trueper = true]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-04
      • 2015-12-10
      • 2017-06-17
      • 2013-09-04
      • 1970-01-01
      • 2013-11-27
      相关资源
      最近更新 更多