如何将 "Prince" 库添加到 CodeIgniter?
How to add "Prince" library to CodeIgniter?
我想使用这个库:http://www.princexml.com/ 它可以帮助我从 HTML/XML 文件创建 PDF 文件。
我从这里下载了 PHP zip 文件:http://www.princexml.com/download/wrappers/ 并将其添加到 codeigniter 目录中我的 "libraries" 文件夹中。
据我所知,我只需要 include/call 图书馆并定期使用它的功能。
https://ellislab.com/codeigniter/user-guide/general/creating_libraries.html
我正在使用 WAMP (Windows),所以我在找到 prince.exe 的地方为 C:\Program Files (x86)\Prince\engine\bin
创建了一个别名,并将其命名为 "prince" (http://localhost/prince
)。
我的控制器上有这个:
public function banana(){
$this->load->library('prince');
$prince = new Prince('http://localhost/prince/prince.exe');
$xmlPath = 'http://localhost/temp/test.html';
$this->prince->convert_file_to_passthru($xmlPath);
}
我遇到了这些错误:
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Prince::__construct(), called in
C:\wamp\www\tools\system\core\Loader.php on line 1247 and defined
Filename: libraries/prince.php
Line Number: 48
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 48
Function: _error_handler
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line:
304 Function: library
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: exePath
Filename: libraries/prince.php
Line Number: 50
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 50
Function: _error_handler
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line:
304 Function: library
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
A PHP Error was encountered
Severity: Warning
Message: proc_open(): CreateProcess failed, error code - 87
Filename: libraries/prince.php
Line Number: 796
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 796
Function: proc_open
File: C:\wamp\www\tools\application\libraries\prince.php Line: 528
Function: convert_internal_file_to_passthru
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line:
311 Function: convert_file_to_passthru
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
An uncaught Exception was encountered
Type: Exception
Message: Failed to execute "" --structured-log=buffered
"http://localhost/temp/test.html" -o -
Filename: C:\wamp\www\tools\application\libraries\prince.php
Line Number: 814
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 528
Function: convert_internal_file_to_passthru
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line:
311 Function: convert_file_to_passthru
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
这是我第一次 运行 来自 CodeIgniter 的外部库,我不确定该怎么做,codeigniter 文档没有提及太多信息。
创建 ALIAS 无效,所以我认为这就是它无法识别 exePath
变量的原因。
如何使用所有 "Prince" 库并使其在 CodeIgniter 上运行?
你应该试试这个:
public function banana(){
// it should be a local path instead of URL
$exe_path = 'c:\some_folder\prince\prince.exe';
// you can add parameter for the constructor call
$this->load->library('prince', $exe_path);
// it also should be a local path where the folder should be writable by apache
$xmlPath = 'c:\some_folder\temp\test.html';
$this->prince->convert_file_to_passthru($xmlPath);
}
要将 "Prince" 用作 CI 上的库:
将 Prince.php 添加到库文件夹 (/application/library/Prince.php) 并确保文件名首字母大写。
要将变量传递给库,必须使用数组而不是简单的字符串来完成。 $exePath = array('exePath' => 'C:\Program Files (x86)\Prince\engine\bin\prince.exe');
public function banana(){
// it should be a local path instead of URL
$exePath = array('exePath' => 'C:\Program Files (x86)\Prince\engine\bin\prince.exe');
// you can add parameter for the constructor call
$this->load->library('prince', $exePath);
// it also should be a local path where the folder should be writable by apache
$xmlPath = 'C:\wamp\www\tools\files\banana\test.html';
$pdfPath = 'C:\wamp\www\tools\files\banana\test.pdf';
$this->prince->convert_file_to_file($xmlPath, $pdfPath);
}
构造将变量作为数组获取,而不是像它应该的那样作为字符串获取!所以我稍微编辑了 __construct
:
public function __construct($exePathArr)
{
// var_dump($exePathArr);
$exePath = "banana"; // just to make sure that this var is a string :P
// var_dump($exePath);
$exePath = $exePathArr['exePath'];
// var_dump($exePath);
$this->exePath = $exePath;
$this->styleSheets = '';
$this->scripts = '';
...
.......
..........
这是在 "Prince" 网站中打开的 post:
http://www.princexml.com/forum/topic/3318/princexml-and-codeigniter-how-to-add-the-library?p=1#16234
希望这对也有需要的人有所帮助。
我在 WAMP 和 UBUNTU 服务器上测试了这个。
我想使用这个库:http://www.princexml.com/ 它可以帮助我从 HTML/XML 文件创建 PDF 文件。
我从这里下载了 PHP zip 文件:http://www.princexml.com/download/wrappers/ 并将其添加到 codeigniter 目录中我的 "libraries" 文件夹中。 据我所知,我只需要 include/call 图书馆并定期使用它的功能。 https://ellislab.com/codeigniter/user-guide/general/creating_libraries.html
我正在使用 WAMP (Windows),所以我在找到 prince.exe 的地方为
C:\Program Files (x86)\Prince\engine\bin
创建了一个别名,并将其命名为 "prince" (http://localhost/prince
)。
我的控制器上有这个:
public function banana(){
$this->load->library('prince');
$prince = new Prince('http://localhost/prince/prince.exe');
$xmlPath = 'http://localhost/temp/test.html';
$this->prince->convert_file_to_passthru($xmlPath);
}
我遇到了这些错误:
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Prince::__construct(), called in C:\wamp\www\tools\system\core\Loader.php on line 1247 and defined
Filename: libraries/prince.php
Line Number: 48
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 48 Function: _error_handler
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line: 304 Function: library
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: exePath
Filename: libraries/prince.php
Line Number: 50
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 50 Function: _error_handler
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line: 304 Function: library
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
A PHP Error was encountered
Severity: Warning
Message: proc_open(): CreateProcess failed, error code - 87
Filename: libraries/prince.php
Line Number: 796
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 796 Function: proc_open
File: C:\wamp\www\tools\application\libraries\prince.php Line: 528 Function: convert_internal_file_to_passthru
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line: 311 Function: convert_file_to_passthru
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
An uncaught Exception was encountered
Type: Exception
Message: Failed to execute "" --structured-log=buffered "http://localhost/temp/test.html" -o -
Filename: C:\wamp\www\tools\application\libraries\prince.php
Line Number: 814
Backtrace:
File: C:\wamp\www\tools\application\libraries\prince.php Line: 528 Function: convert_internal_file_to_passthru
File: C:\wamp\www\tools\application\controllers\aso\Cli_kas.php Line: 311 Function: convert_file_to_passthru
File: C:\wamp\www\tools\index.php Line: 292 Function: require_once
这是我第一次 运行 来自 CodeIgniter 的外部库,我不确定该怎么做,codeigniter 文档没有提及太多信息。
创建 ALIAS 无效,所以我认为这就是它无法识别 exePath
变量的原因。
如何使用所有 "Prince" 库并使其在 CodeIgniter 上运行?
你应该试试这个:
public function banana(){
// it should be a local path instead of URL
$exe_path = 'c:\some_folder\prince\prince.exe';
// you can add parameter for the constructor call
$this->load->library('prince', $exe_path);
// it also should be a local path where the folder should be writable by apache
$xmlPath = 'c:\some_folder\temp\test.html';
$this->prince->convert_file_to_passthru($xmlPath);
}
要将 "Prince" 用作 CI 上的库:
将 Prince.php 添加到库文件夹 (/application/library/Prince.php) 并确保文件名首字母大写。
要将变量传递给库,必须使用数组而不是简单的字符串来完成。
$exePath = array('exePath' => 'C:\Program Files (x86)\Prince\engine\bin\prince.exe');
public function banana(){ // it should be a local path instead of URL $exePath = array('exePath' => 'C:\Program Files (x86)\Prince\engine\bin\prince.exe');
// you can add parameter for the constructor call $this->load->library('prince', $exePath); // it also should be a local path where the folder should be writable by apache $xmlPath = 'C:\wamp\www\tools\files\banana\test.html'; $pdfPath = 'C:\wamp\www\tools\files\banana\test.pdf'; $this->prince->convert_file_to_file($xmlPath, $pdfPath);
}
构造将变量作为数组获取,而不是像它应该的那样作为字符串获取!所以我稍微编辑了
__construct
:public function __construct($exePathArr) { // var_dump($exePathArr); $exePath = "banana"; // just to make sure that this var is a string :P // var_dump($exePath); $exePath = $exePathArr['exePath']; // var_dump($exePath); $this->exePath = $exePath; $this->styleSheets = ''; $this->scripts = ''; ... ....... ..........
这是在 "Prince" 网站中打开的 post: http://www.princexml.com/forum/topic/3318/princexml-and-codeigniter-how-to-add-the-library?p=1#16234
希望这对也有需要的人有所帮助。
我在 WAMP 和 UBUNTU 服务器上测试了这个。