2013-08-16 67 views
0

我正在使用Yii框架進行web開發。在Yii中需要命令PHP

我正在嘗試使電子郵件cron工作,爲此我使用PHPMailer。

這裏是我的配置/ console.php

> return array(
>  'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..', 
>  'name'=>'My Console Application', 
> 
>  // preloading 'log' component 
>  'preload'=>array('log'), 
>  'import'=>array(
>    'application.modules.*', 
>    'application.extensions.*', 
>    'application.components.*', 
>    'application.models.*', 
>  ), .... 

命令/ testCommand.php

class UptimeCheckerCommand extends CConsoleCommand{ 
    public function run($args) { 
.... 
$warning->send(); 
.... 

COMPONE NT/Warning.php

.... 
require("/protected/extensions/PHPMailer/class.phpmailer.php"); 
.... 

錯誤報告:

PHP Error[2]: require(/protected/extensions/PHPMailer/class.phpmailer.php): fail 
ed to open stream: No such file or directory 

我使用的控制器部分已經測試它和它的作品完美的罰款。錯誤只發生在我試圖使用yiic test命令訪問它時。

任何幫助將不勝感激

+0

將require語句更改爲'require(「./ protected/extensi ...」)'時會發生同樣的錯誤嗎? – fijas

回答

0

感謝您的快速回復。

我已經嘗試了上面的一些建議。

來自的建議Andrey Shatilov沒有工作。

而且從烏斯曼建議阿拉姆mazraara改變:

要求( 「/保護/擴展/ PHPMailer的/ class.phpmailer.php」);

的Yii ::進口( 'application.extensions.PHPMailer.class.phpmailer.php');

無法工作或者是因爲文件名中有(class.phpmailer.php)

,因爲它點綴,警予想我的類文件夾,而不是在class.phpmailer要求phpmailer.php。 PHP

,工程代碼:

要求( 「../保護/擴展/ PHPMailer的/ class.phpmailer.php」);

不知道爲什麼這個工作,因爲我在testCommand.php和/protected/command/testCommand.php在/保護/擴展/ PHPMailer的我PHPMailer的文件/但它的作品。

2
'import'=>array(
    ... 
    'application.extensions.PHPMailer.*', 
    ... 
) 

和重命名文件class.phpmailer.phpPHPMailer.php

導入目錄不會導入任何子目錄。

1

試試這樣說:

$mailer = Yii::import('application.extensions.phpmailer'); 

然後用$郵件發送電子郵件

1

這是最合適的。在我的percepective ...

Yii::import('application.extensions.phpmailer'); 

然後你可以用這種方式創建一個對象並做必要的事情。

$mail = new PHPMailer();