2012-12-14 36 views
2

我試圖創建使用此命令的cPanel cron作業:cron作業 - 笨 - 類 '是CI_Controller' 未找到

/usr/bin/php -q /home/mystuff/public_html/application/controllers/scripts.php scripts release_reviews 

我scripts.php控制器如下:

<?php 

class Scripts extends CI_Controller 
{ 
    public function __construct() 
    { 
     parent::__construct(); 

     if (!$this->input->is_cli_request()) show_error('Direct access is not allowed'); 

    } 

    public function release_reviews() 
    { 
     echo release_reviews(); //where the actual logic will sit once the cron job works 
    } 
} 

我得到的,當我嘗試運行cron作業反饋: 致命錯誤:類「是CI_Controller」在/home/mystuff/public_html/application/controllers/scripts.php沒有找到上線

我無法找到任何證據,任何人有和我同樣的問題 - 解決這個最具話題做和我一樣,它工作得很好明顯。

非常感謝!

回答

0

沒有CI_Controller類。 CRON職位只加載該文件,所以它無法找到任何CI_Controller。你將不得不包括類定義之前CI_CONTROLLER

像這樣的事情

<?php 

require_once('path_to_CI_controller'); 

class Scripts extends CI_Controller 
{ 
    ... 
3

要通過命令行訪問CodeIgnter,你要撥打的index.php文件,而不是你的控制器。

php /home/mystuff/public_html/index.php scripts release_reviews 

文檔:http://ellislab.com/codeigniter/user-guide/general/cli.html

+0

我已經試過正是但現在說 「404找不到網頁」。然而,index.php絕對位於我所說的地方。 – Davor

+0

這可能聽起來很愚蠢,但是這樣做的工作:http://stackoverflow.com/a/11156257 –

+0

我其實只是嘗試,以及 - 如果我添加「本地」cron作業不會再運行。所以這似乎不是問題。 – Davor

0

用於路由文件中的以下和它的工作! 我明白了這一點。我的新手問題是參數需要配置。

例如

`$route['pdfscript/runmethod'] = "batch/pdfscript/runmethod"; 
$route['pdfscript/runmethod/(:any)'] = "batch/pdfscript/runmethod/$1";' 

`pdfscript.php 
<?php 
class pdfscript extends CI_Controller { 
public function runmethod($file) { 
echo $file; 
.....` 

CMD線>的php.exe的index.php pdfscript runmethod名