Pear mail_queue with Yii

I am trying to use the Pear mail_queue library with Yii so I can send notification mails to users after comments have been made on a discussion thread. Without the queue, the save button hangs waiting to send mails.

I have installed Pear Mail_Queue on my server and have confirmed it is working.

I cannot see how to reference it in Yii

I have tried


 require_once 'Mail/Queue.php';

 $queue =& new Mail_Queue($db_options, $mail_options);

but get the error message


<p>include(Mail_Queue_Container_.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory (/var/www/yii-read-only/framework/yiilite.php:217)</p>

<pre>#0 /var/www/yii-read-only/framework/yiilite.php(217): CWebApplication->handleError()

#1 /var/www/yii-read-only/framework/yiilite.php(217): autoload()

Any help to reference this library would be appreciated it

Note: I did read this link http://www.yiiframework.com/doc/guide/1.1/en/extension.integration but did not want to save the Mail_Queue files inside the local Yii project folder.

As i see, you got problem with Yii build-in autoload, it can’t load your Mail_Queue_Container_.php. Not so long ago i got same problem with my project. The solution I found:

[list=2]

[*]Write custom autoload in Yii class (framework/yii.php).


public static function customAutoload($class){...}

[*]Register it at the end of yii.php file (not in the class).


class Yii extends YiiBase{...}

Yii::registerAutoloader(array('Yii','customAutoload'));

[/list]

Thanks. What will happen when I upgrade Yii next time? I suppose I will lose those changes and have to remember to put back in. Is there a way to extend a class somewhere so they are not lost?

I use pear extensions with yii well without any auto load functions. just use require_once(‘Testing/Selenium.php’); in your index.php

Thanks for your suggestion. I tried that in index.php so at the bottom of the file it looks like




require_once($yii);

require_once 'Mail/Queue.php';

Yii::createWebApplication($config)->run();

No error is shown at this point, but when


  $queue =& new Mail_Queue($db_options, options);

  $mime =& new Mail_mime();

is called later, the following error still appears


<h1>PHP Error [2]</h1>

<p>include(Mail_Queue_Container_.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory (/var/www/yii-read-only/framework/yiilite.php:217)</p>

<pre>#0 /var/www/yii-read-only/framework/yiilite.php(217): CWebApplication->handleError()

#1 /var/www/yii-read-only/framework/yiilite.php(217): autoload()

#2 unknown(0): autoload()

#3 unknown(0): spl_autoload_call()

#4 /usr/lib/php/Mail/Queue.php(217): class_exists()

#5 /usr/lib/php/Mail/Queue.php(174): Mail_Queue->Mail_Queue()

I checked again. The Pear class for Mail_Queue is definitely being loaded on the require_once and is referenced. When I leave out the parameters for this on calling it $temp = Mail_Queue(); I get an error saying parameter is not defined properly and showing me that it is pulling it from /usr/local/lib/php/Mail

When I put the parameters in properly, I get the same error again as above.

Still stuck, but trying to solve

** SOLUTION **

See solution here http://www.yiiframework.com/forum/index.php?/topic/16855-yii-and-3rd-pary-libraries/

Just a note, modifying any of Yii’s framework files is never a good idea unless you’re prepared to maintain what essentially becomes your fork of the Yii framework, just for your application(s). With current versioning systems (hg, git), it’s a simple matter to keep up-to-date nowadays, but that’s still not the best approach.

Whenever you need functionality from Yii that doesn’t already exist, then the solution is to extend the Yii library that is missing that feature. If you find that you must modify Yii’s framework files, then you’re still probably doing it wrong, as again that should never be the solution unless you are prepared to maintain your own fork.

Cheers