yiiext / zend-autoloader-component

Fast autoloader for Zend Framework classes.
http://www.yiiframework.com/extension/zendautoloader
5 stars 1 forks source link

No such file or directory #5

Closed GerhardLiebenberg closed 10 years ago

GerhardLiebenberg commented 10 years ago

Hi

I'm trying to test zend email in a Yii "console" script.

The console command calls a behavior in common/extensions/behaviors/....

The behavior function has this code: Yii::import('common.extensions.EZendAutoloader', true); EZendAutoloader::$prefixes = array('Zend'); EZendAutoloader::$basePath = Yii::getPathOfAlias('common.lib') . DIRECTORY_SEPARATOR; Yii::registerAutoloader(array("EZendAutoloader", "loadClass"), true);

This code works fine: $tr = new Zend_Mail_Transport_Sendmail('-freturn_to_me@example.com'); Zend_Mail::setDefaultTransport($tr); $mail = new Zend_Mail(); $mail->setBodyText('This is the text of the mail.'); $mail->setFrom('somebody@example.com', 'Some Sender'); $mail->addTo('somebody_else@example.com', 'Some Recipient'); $mail->setSubject('TestSubject'); $mail->send();

But if I change the first row to: $tr = new Zend_Mail_Transport_Smtp('mail.example.com');

Then this error follows: include(Zend/Validate/Hostname/Com.php): failed to open stream: No such file or directory (C:\xampp\htdocs\iccap\common\lib\Zend\Validate\Hostname.php:586)

Line 586 of Hostname.php is: $regexChars += include($this->_validIdns[strtoupper($this->_tld)]);

So it looks like this 'include' is not working. Any ideas?

samdark commented 10 years ago

Do you have that file?

samdark commented 10 years ago

Include should not be affected by autoload.

GerhardLiebenberg commented 10 years ago

Yes, I have the Zend/Validate/Hostname/Com.php file. I have the whole zend library included in Yii bootstrap.

samdark commented 10 years ago

Try adjusting your PHP include path. It doesn't seem to be related with autoloading at all.

GerhardLiebenberg commented 10 years ago

I have this: Yii::setPathOfAlias('common', $root . DIRECTORY_SEPARATOR . 'common'); Yii::setPathOfAlias('Zend', $root . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'Zend');

This works: include('common/lib/Zend/Validate/Hostname/Com.php');

This throws the error: include('Zend/Validate/Hostname/Com.php');

samdark commented 10 years ago

Yeah, that's include path of your PHP. You need to do set_include_path('zend/library/dir'.get_include_path()).

GerhardLiebenberg commented 10 years ago

Thank you Alexander

I had to do set_include_path('common/lib;' . get_include_path()) in the code - (note the semicolon after common/lib;) OR I could add 'common.lib.*' to the 'import' array in config/main.php

I thought the problem was the last part of the path, but it was the first part of the path.