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
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'));
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 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.
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.