Php 在CodeIgniter中加载外部库Gantii时出错
我正在尝试将其集成到我的PHP项目中: 我已将calendar.php和gantii.php复制到应用程序/库中 控制器:Php 在CodeIgniter中加载外部库Gantii时出错,php,codeigniter,libraries,Php,Codeigniter,Libraries,我正在尝试将其集成到我的PHP项目中: 我已将calendar.php和gantii.php复制到应用程序/库中 控制器: <?php class summary extends CI_Controller { function index() { $this->load->library('gantti'); $gantti = new Gantti($data, array( 'title' => '', 'cellwi
<?php
class summary extends CI_Controller {
function index() {
$this->load->library('gantti');
$gantti = new Gantti($data, array(
'title' => '',
'cellwidth' => 25,
'cellheight' => 35,
'today' => true
));
$this->load->view('summary_view', $gantti);
}
}
load->library`若要加载CI中的任何库,它将自动调用其构造函数,此库中发生的情况与此库中发生的情况相同,但您需要至少向库传递一个参数,这就是它出错的原因,您只能使用CI loader向库传递一个参数
但是您不能将第二个参数设置为此库,但是此库中的所有变量都是公共的。您可以这样调用它们来设置它们
$this->gantti->options = array(
'title' => '',
'cellwidth' => 25,
'cellheight' => 35,
'today' => true
)
完全解
$this->load->library('gantti',$data); //first load library and pass data
$this->gantti->options = array(
'title' => '',
'cellwidth' => 25,
'cellheight' => 35,
'today' => true
);
$data['gantti'] = $this->gantti->__toString();
另一个解决方案是创建一个自定义库,并使用甘蒂库扩展它。在库目录下复制甘蒂库目录
自定义库
<?php
require_once APPPATH.'libraries/lib/gantti.php';
class cigantti extends Gantti {
//put your code here
public function __construct() {
}
public function generate($data = array(), $params = array()){
parent::__construct($data, $params);
return $this->render();
}
}
?>
请显示
system\core\Loader.php
的代码。删除$this->load->library('gantti')代码>:它不向构造函数传递参数,但包含类。无需发布Loader.phpcode@DamienPirsy致命错误:require():无法在第3行的C:\xampp\htdocs\bit\application\views\summary\u view.php中打开所需的“lib/gantti.php”(include_path=”;C:\xampp\php\PEAR)
$this->gantti->options = array(
'title' => '',
'cellwidth' => 25,
'cellheight' => 35,
'today' => true
)
$this->load->library('gantti',$data); //first load library and pass data
$this->gantti->options = array(
'title' => '',
'cellwidth' => 25,
'cellheight' => 35,
'today' => true
);
$data['gantti'] = $this->gantti->__toString();
<?php
require_once APPPATH.'libraries/lib/gantti.php';
class cigantti extends Gantti {
//put your code here
public function __construct() {
}
public function generate($data = array(), $params = array()){
parent::__construct($data, $params);
return $this->render();
}
}
?>
$this->load->library('cigantti');
$data['gantti'] = $this->cigantti->generate($data, array(
'title' => 'Demo',
'cellwidth' => 25,
'cellheight' => 35,
'today' => true
));