Note: Latest release and documentation are available from component github page.
Allows to efficiently load Zend Framework classes without need to additionally call require_once() or Yii::import().
Installation ¶
Extension ¶
Unpack extension to protected/extensions/
.
Zend Framework ¶
Copy ZF directory Zend
to protected/vendors/
.
You can use special service to get only required
ZF classes.
Stripping all require_once from ZF ¶
It is required for this extension and allows to load ZF classes faster.
You can do search-replace from your IDE: search require_once
replace to //require_once
.
Altenatively you can use console:
GNU: ~~~ % cd path/to/ZendFramework/library % find . -name '.php' -not -wholename '/Loader/Autoloader.php' \ -not -wholename '*/Application.php' -print0 | \ xargs -0 sed --regexp-extended --in-place 's/(require_once)/\/\/ \1/g' ~~~
MacOSX: ~~~ % cd path/to/ZendFramework/library % find . -name '.php' | grep -v './Loader/Autoloader.php' | \ xargs sed -E -i~ 's/(require_once)/\/\/ \1/g' % find . -name '.php~' | xargs rm -f ~~~
Updating your index.php ¶
We need to register loader before application is run:
define('YII_DEBUG', true);
$webRoot=dirname(__FILE__);
require_once(dirname($webRoot).'/framework/yii.php');
$configFile=$webRoot.'/../protected/config/main.php';
$app = Yii::createWebApplication($configFile);
// you can load not only Zend classes but also other classes with the same naming
// convention
EZendAutoloader::$prefixes = array('Zend', 'Custom');
Yii::import("ext.yiiext.components.zendAutoloader.EZendAutoloader", true);
Yii::registerAutoloader(array("EZendAutoloader", "loadClass"), true);
$app->run();
Changelog ¶
1.1.1 ¶
- Fixed autoloader registration order in readme (Sam Dark)
1.1 ¶
- Ability to load custom code that is using Zend class naming convention but with different prefix.
1.0 ¶
- Initial public release.
This didn't work for me until...
// First Import the extension Yii::import("ext.yiiext.components.zendAutoloader.EZendAutoloader", true); // And then call the loaded class EZendAutoloader::$prefixes = array('Zend', 'Custom'); Yii::registerAutoloader(array("EZendAutoloader", "loadClass"));
this extension is a part of yiiext;
you needn't use the sample way to import this ext;
just put it to components dir or extension dir , and shorten the deep of dir path:
backwardselvis is right , we should firs import the EZendAutoloader,and then set the static prefixes var :
// First Import the extension Yii::import("ext.yiiext.EZendAutoloader", true); //or Yii::import("application.components.yiiext.EZendAutoloader", true); // And then call the loaded class EZendAutoloader::$prefixes = array('Zend', 'Custom'); Yii::registerAutoloader(array("EZendAutoloader", "loadClass"));
Wrong path
When I want to use this extension, I got an error:
include_once(Zend/Uri/Http.php): failed to open stream: No such file or directory
My code:
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME; $client = Zend_Gdata_ClientLogin::getHttpClient($username, $password, $service); $docs = new Zend_Gdata_Docs($client); $feed = $docs->getDocumentListFeed(); $this->render('index', array('feed', $feed));
My log:
~~~
2011/12/10 21:19:13 [error] [php] include_once(Zend/Uri/Http.php): failed to open stream: No such file or directory (/var/www/modultest.dev/protected/vendors/Zend/Loader.php:146)
Stack trace:
0 /var/www/modultest.dev/protected/vendors/Zend/Uri.php(137): loadClass()
1 /var/www/modultest.dev/protected/vendors/Zend/Http/Client.php(305): factory()
2 /var/www/modultest.dev/protected/vendors/Zend/Gdata/ClientLogin.php(106): Zend_Gdata_HttpClient->setUri()
3 /var/www/modultest.dev/protected/modules/ZendTest/controllers/DefaultController.php(8): getHttpClient()
4 /var/www/modultest.dev/framework/web/actions/CInlineAction.php(50): DefaultController->actionIndex()
5 /var/www/modultest.dev/framework/web/CController.php(300): CInlineAction->runWithParams()
6 /var/www/modultest.dev/framework/web/CController.php(278): DefaultController->runAction()
7 /var/www/modultest.dev/framework/web/CController.php(257): DefaultController->runActionWithFilters()
8 /var/www/modultest.dev/framework/web/CWebApplication.php(277): DefaultController->run()
9 /var/www/modultest.dev/framework/web/CWebApplication.php(136): CWebApplication->runController()
10 /var/www/modultest.dev/framework/base/CApplication.php(158): CWebApplication->processRequest()
11 /var/www/modultest.dev/index.php(22): CWebApplication->run()
Can anyone help me?
all files in right place?
@shark:
is your Zend library under
protected/vendors/Zend
and isUri/Http.php
under there? Make sure you put all files in the right directories.Re: all files in right place?
@CeBe:
Yes, they are.
Bugs on github!
@shark: created an issue on github: https://github.com/yiiext/zend-autoloader-component/issues/1
Please discuss there to not spam people who follow this extension.
stripping requrire_once
What is about include_once, include and require, should I strip them,too?
They appear in many files.
@yiibie
There are no require, include or include_once in Zend code.
EDIT: Actually, there are some of them on the code. They aren't causing me issues, though.
Tweaking the Zend code
Well, in the end I had some issues with Zend trying to include code.
My fixes:
return
statement in the beginning of Zend_Loader::loadClass.$regexChars = array()
or you'll need to disable the foreach below in the file.If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.