Search code examples
phpyiiphpmailer

Require command in Yii PHP


I'm using Yii framework for my web development.

I'm trying to make email cron job, for this i'm using PHPMailer.

here's my config/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.*',
>         ), ....

my command/testCommand.php

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

my component/Warning.php

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

Error Report:

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

I'm already testing it using controller to the component and it works perfectly fine. The error only happens when I'm trying to access it using yiic test command.

Any help will be appreciated


Solution

  • Thanks for the quick reply.

    I already tried a few suggestion from above.

    The suggestion from Andrey Shatilov didn't work.

    And for suggestion from usman allam and mazraara to change:

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

    with

    Yii::import('application.extensions.PHPMailer.class.phpmailer.php');

    can't work either because the file name has dot in it (class.phpmailer.php)

    because of it, yii thought i request phpmailer.php in class folder instead of class.phpmailer.php

    The code that works :

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

    Don't know why this works because my testCommand.php in /protected/command/testCommand.php and my phpmailer file in /protected/extensions/PHPMailer/ but it works.