我正在尝试将其集成到我的PHP项目中:https://github.com/bastianallgeier/gantti
我已将calendar.php和gantii.php复制到应用程序/库中。
控制器:
<?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);
}
}
看法:
<?php
require('lib/gantti.php');
require('controllers/summary.php');
date_default_timezone_set('UTC');
setlocale(LC_ALL, 'en_US');
?>
<!DOCTYPE html>
<html>
<head>
<title>Summary</title>
<meta charset="utf-8" />
<link href="<?php echo base_url(); ?>assets/css/gantti.css" rel="stylesheet" media="screen">
<link href="<?php echo base_url(); ?>assets/css/metro-bootstrap.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery-1.10.2.js"></script>
</head>
<body>
<div class="page-header">
<h1>Summary</h1>
</div>
<?php echo $gantti ?>
</body>
</html>
但没有查看该页面,而是收到如下错误(404):
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Gantti::__construct(), called in C:\xampp\htdocs\wwww\system\core\Loader.php on line 1099 and defined
Filename: libraries/gantti.php
Line Number: 18
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: libraries/gantti.php
Line Number: 29
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: libraries/gantti.php
Line Number: 41
Fatal error: Call to a member function month() on a non-object in C:\xampp\htdocs\www\application\libraries\gantti.php on line 58
load-> library`加载CI中的任何库,它将自动调用其构造函数,此库中发生的事情相同,但是您需要将至少一个参数传递给库,这就是为什么它给出错误的原因,您只能将一个参数传递给使用ci loader的库
$this->load->library('gantti',$data);
但是您不能设置第二个参数来设置该库,但是该库中的所有变量都是公共的,您可以像这样调用它们来设置它们
$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();
另一个解决方案是创建一个自定义库,并使用库目录下的Gantti库复制gantti lib目录对其进行扩展
定制图书馆
<?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
));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句