Yii Framework Forum: Yii and 3rd pary libraries - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii and 3rd pary libraries Pear Rate Topic: -----

#1 User is offline   Alan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 14-December 10
  • Location:Tokyo, Japan

Posted 03 March 2011 - 09:32 AM

I looked at the link for using 3rd party libraries http://www.yiiframew...ion.integration and have tried many ideas, but cannot get PEAR Mail_Queue to work with Yii

The require_once 'Mail/Queue.php'; works fine in that it finds the Queue.php file properly, but when I call the Class

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

I get the following error

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/YiiBase.php(396)

384      * @return boolean whether the class has been loaded successfully
385      */
386     public static function autoload($className)
387     {
388         // use include so that the error PHP file may appear
389         if(isset(self::$_coreClasses[$className]))
390             include(YII_PATH.self::$_coreClasses[$className]);
391         else if(isset(self::$classMap[$className]))
392             include(self::$classMap[$className]);
393         else
394         {
395             if(strpos($className,'\\')===false)
396                 include($className.'.php');
397             else  // class name with namespace in PHP 5.3
398             {
399                 $namespace=str_replace('\\','.',ltrim($className,'\\'));
400                 if(($path=self::getPathOfAlias($namespace))!==false)
401                     include($path.'.php');
402                 else
403                     return false;
404             }
405             return class_exists($className,false) || interface_exists($className,false);
406         }
407         return true;
408     }


/var/www/yii-read-only/framework/YiiBase.php(396): YiiBase::autoload()

391         else if(isset(self::$classMap[$className]))
392             include(self::$classMap[$className]);
393         else
394         {
395             if(strpos($className,'\\')===false)
396                 include($className.'.php');
397             else  // class name with namespace in PHP 5.3
398             {
399                 $namespace=str_replace('\\','.',ltrim($className,'\\'));
400                 if(($path=self::getPathOfAlias($namespace))!==false)
401                     include($path.'.php');

#1 	
 unknown(0): YiiBase::autoload("Mail_Queue_Container_")
#2 	
 unknown(0): spl_autoload_call("Mail_Queue_Container_")
#3 	
+
–
 /home/goalchec/dev/protected/vendors/Mail/Queue.php(217): class_exists("Mail_Queue_Container_")

212         $container_classfile = $container_type . '.php';
213 
214         // Attempt to include a custom version of the named class, but don't treat
215         // a failure as fatal.  The caller may have already included their own
216         // version of the named class.
217         if (!class_exists($container_class)) {
218             include_once 'Mail/Queue/Container/' . $container_classfile;
219         }
220         if (!class_exists($container_class)) {
221             array_push($this->_initErrors, new Mail_Queue_Error(MAILQUEUE_ERROR_UNKNOWN_CONTAINER,
222                 $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__));



Has anyone had success with this. On the main Yii page, it says it integrates with PEAR, but I cannot see how to get this to work
0

#2 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 604
  • Joined: 08-May 09

Posted 03 March 2011 - 09:41 AM

how do you import mail_queue?
0

#3 User is offline   Alan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 14-December 10
  • Location:Tokyo, Japan

Posted 03 March 2011 - 09:52 AM

View Postmbi, on 03 March 2011 - 09:41 AM, said:

how do you import mail_queue?


I thought since Pear was referenced it was not needed.

I did try copying the Mail_Queue files to a folder under protected/vendors/Mail (even thought that was not my preferred option) and then using

Yii::import('application.vendors.*');
require_once 'Mail/Queue.php';

but the error was the same

Appreciate you taking a look at it
0

#4 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 604
  • Joined: 08-May 09

Posted 03 March 2011 - 10:21 AM

yii tries to include a file

include(Mail_Queue_Container_.php)


that doesnt exist. Seems you have to check any configurations?
see http://pear.php.net/...ue.tutorial.php
0

#5 User is offline   Alan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 14-December 10
  • Location:Tokyo, Japan

Posted 03 March 2011 - 10:37 AM

View Postmbi, on 03 March 2011 - 10:21 AM, said:

yii tries to include a file

include(Mail_Queue_Container_.php)


that doesnt exist. Seems you have to check any configurations?
see http://pear.php.net/...ue.tutorial.php


How can I stop Yii trying to include that? What configurations might need checking to solve that?
0

#6 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 604
  • Joined: 08-May 09

Posted 03 March 2011 - 10:54 AM

what are your $db_options?
is there something like

$db_options['type'] = 'mdb2';

0

#7 User is offline   Alan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 14-December 10
  • Location:Tokyo, Japan

Posted 03 March 2011 - 08:43 PM

View Postmbi, on 03 March 2011 - 10:54 AM, said:

what are your $db_options?
is there something like

$db_options['type'] = 'mdb2';



I was first trying $db['type'] = 'db'; but have tried mdb2 and other options. It doesnt seem to matter what I put as the options, Yii is still trying to access Mail_Queue_Container_.php which doesnt exist which is the problem

Thanks
0

#8 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 04 March 2011 - 05:16 AM

You still need to include the PEAR class manually. Yii's autoloader is not compatible with PEAR's class naming scheme.

http://pear.php.net/...ue.tutorial.php


require_once "Mail/Queue.php";


EDIT: Sorry, replied to fast, you already tried that...

This post has been edited by Mike: 04 March 2011 - 05:17 AM

0

#9 User is offline   Alan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 14-December 10
  • Location:Tokyo, Japan

Posted 04 March 2011 - 07:22 AM

View PostMike, on 04 March 2011 - 05:16 AM, said:

You still need to include the PEAR class manually. Yii's autoloader is not compatible with PEAR's class naming scheme.

http://pear.php.net/...ue.tutorial.php


require_once "Mail/Queue.php";


EDIT: Sorry, replied to fast, you already tried that...


Appreciate you taking a look at it. It appears difficult to achieve,but I am sure it should be possible. Are there any other suggestions perhaps? Should I rename the mail_queue class in some way?
0

#10 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 04 March 2011 - 07:26 AM

Do not rename. PEAR usually includes any required class file before it is used. Find out, why PEAR doesn't do that in this case. If the class file is not loaded, Yii's autoloader tries to find it (which makes no sense here). That's why you get the error.
0

#11 User is offline   Alan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 14-December 10
  • Location:Tokyo, Japan

  Posted 04 March 2011 - 10:50 AM

View PostMike, on 04 March 2011 - 07:26 AM, said:

Do not rename. PEAR usually includes any required class file before it is used. Find out, why PEAR doesn't do that in this case. If the class file is not loaded, Yii's autoloader tries to find it (which makes no sense here). That's why you get the error.


** SOLVED **
Since this proved quite a challenge, but was a simple answer in the end, I wanted to post the solution for this problem.

Using PEAR mail_queue, there are a number of other possible classes which may be called separate to the main Mail_Queue class.

I had been trying the following

 require_once 'Mail/Queue.php';
 $db['type']         = 'db';
 $db['dsn']          = 'mysql://_____<my db settings>________'
 $db['mail_table']   = 'mail_queue';
 $options['driver']  = 'smtp';
 ... other options ...
 $mail_queue =& new Mail_Queue($db, options);
 $mime =& new Mail_mime();


I kept receiving an error saying the container class could not be found.

I tried also to copy the Pear Mail library to a protected/vendors/Mail folder in an attempt to make it work and used Yii::import('application.vendors.*'); but in the end this was not necessary and I was able to not put the files in the vendors folder, but pull them from the centrally included Pear folder without using Yii:import at all

What I found as the solution was I only needed to add 1 more line to make it all work.

 require_once 'Mail/Queue.php';
 require_once 'Mail/Queue/Container/db.php';
 $db['type']         = 'db';
 $db['dsn']          = 'mysql://_____<my db settings>________'
 $db['mail_table']   = 'mail_queue';
 $options['driver']  = 'smtp';
 ... other options ...
 $mail_queue =& new Mail_Queue($db, options);
 $mime =& new Mail_mime();


The missing line was a require_once reference to the database container I wanted to use.

I spent a week on this to end up finding the problem was this line. Next time I will have to focus my investigative skills a bit harder to work out the problem.

If anyone else comes across this type of issue, hope it helps.

Yii performs perfectly with the rest of the library. I am going to set up a cron job for it next and plan to use the following article to guide me on that. http://www.yiiframew...-jobs-with-yii/

Thanks to the other members who chipped in with advice. Much aprpeciated
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users