0
我有一個CodeIgniter項目,我想通過CLI調用我的一個控制器方法,但正常屬性&連接到CI超級對象的方法似乎丟失了?通過CLI運行CodeIgniter腳本 - 缺失CI超級對象方法
例如,運行運行在正常的HTTP請求時完全沒有下面的腳本產生一個錯誤:
class Worker extends MY_Controller {
public function __construct() {
if(php_sapi_name() !== 'cli') {
show_404();
}
}
public function test(){
$this->load->library('some_library');
}
}
這是威盛的CLI
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Trying to get property of non-object</p>
<p>Filename: controllers/worker.php</p>
<p>Line Number: 21</p>
</div>PHP Fatal error: Call to a member function library() on a non-object in /Users/casey/Documents/workspaces/vibecompass_live/application/controllers/worker.php on line 21
Fatal error: Call to a member function library() on a non-object in /Users/casey/Documents/workspaces/vibecompass_live/application/controllers/worker.php on line 21
我返回的錯誤這樣調用腳本: $ php index.php工人測試
編輯
此外,此腳本:
class Worker extends MY_Controller {
public function __construct() {
if(php_sapi_name() !== 'cli') {
show_404();
}
}
public function test(){
$CI =& get_instance();
var_dump($CI); die();
$this->load->library('some_library');
}
}
返回:NULL
我想拍我自己。謝謝。類似的問題,我只是沒有想到。 – MikeMurko