簡體   English   中英

如何將“ Prince”庫添加到CodeIgniter?

[英]How to add “Prince” library to CodeIgniter?

我想使用該庫: http : //www.princexml.com/這可以幫助我從HTML / XML文件創建PDF文件。

在我的控制器上有這個:

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);


}

我得到了這些錯誤:

遇到PHP錯誤

嚴重程度:警告

消息:缺少Prince :: __ construct()的參數1,在第1247行的C:\\ wamp \\ www \\ tools \\ system \\ core \\ Loader.php中調用並定義

文件名:libraries / prince.php

行號:48

回溯:

文件:C:\\ wamp \\ www \\ tools \\ application \\ libraries \\ prince.php行:48函數:_error_handler

文件:C:\\ wamp \\ www \\ tools \\ application \\ controllers \\ aso \\ Cli_kas.php行:304功能:庫

文件:C:\\ wamp \\ www \\ tools \\ index.php行:292功能:require_once

遇到PHP錯誤

嚴重程度:注意

消息:未定義的變量:exePath

文件名:libraries / prince.php

行號:50

回溯:

文件:C:\\ wamp \\ www \\ tools \\ application \\ libraries \\ prince.php行:50函數:_error_handler

文件:C:\\ wamp \\ www \\ tools \\ application \\ controllers \\ aso \\ Cli_kas.php行:304功能:庫

文件:C:\\ wamp \\ www \\ tools \\ index.php行:292功能:require_once

遇到PHP錯誤

嚴重程度:警告

消息:proc_open():CreateProcess失敗,錯誤代碼-87

文件名:libraries / prince.php

行號:796

回溯:

文件:C:\\ wamp \\ www \\ tools \\ application \\ libraries \\ prince.php行:796功能:proc_open

文件:C:\\ wamp \\ www \\ tools \\ application \\ libraries \\ prince.php行:528功能:convert_internal_file_to_passthru

文件:C:\\ wamp \\ www \\ tools \\ application \\ controllers \\ aso \\ Cli_kas.php行:311功能:convert_file_to_passthru

文件:C:\\ wamp \\ www \\ tools \\ index.php行:292功能:require_once

遇到未捕獲的異常

類型:異常

消息:無法執行“” --structured-log = buffered“ http://localhost/temp/test.html ” -o-

文件名:C:\\ wamp \\ www \\ tools \\ application \\ libraries \\ prince.php

行號:814

回溯:

文件:C:\\ wamp \\ www \\ tools \\ application \\ libraries \\ prince.php行:528功能:convert_internal_file_to_passthru

文件:C:\\ wamp \\ www \\ tools \\ application \\ controllers \\ aso \\ Cli_kas.php行:311功能:convert_file_to_passthru

文件:C:\\ wamp \\ www \\ tools \\ index.php行:292功能:require_once

這是我第一次從CodeIgniter運行外部庫,我不確定該怎么做,並且codeigniter文檔沒有提及太多信息。

創建ALIAS無效,因此我認為這就是為什么它無法識別exePath的變量的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上的庫:

  1. 將Prince.php添加到庫文件夾(/application/library/Prince.php),並確保文件名的首字母大寫。

  2. 要將變量傳遞給庫,必須使用數組而不是簡單的字符串來完成。 $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); 

    }

  3. 該構造將變量作為數組而不是應有的字符串來獲取! 所以我編輯了__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 = ''; ... ....... ..........

這是在“王子”網站上打開的帖子: http : //www.princexml.com/forum/topic/3318/princexml-and-codeigniter-how-to-add-the-library?p=1#16234

希望這也能幫助需要此服務的人。

我在WAMP和UBUNTU SERVER上都對此進行了測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM