Directory independent extensions

You are viewing revision #5 of this wiki article.
This is the latest version of this article.
You may want to see the changes made in this revision.

« previous (#4)

How to implement directory independent extensions

Many people want to use downloaded extensions in their own way. As for me most of the extensions require me to correct Yii::import() instructions inside their source code. All these extensions are directory dependent. To avoid the situation described above, I suggest to implement pseudo-anonymous aliases:

// take the current extension path
$dir = dirname(__FILE__);
// generate alias name
$alias = md5($dir);
// create alias
Yii::setPathOfAlias($alias,$dir);
// import other classes
Yii::import($alias.'.anotherClass');
Yii::import($alias.'.andAnoTherClass');
//...
//if you want, you can destroy an alias created
Yii::setPathOfAlias($alias,'');

Using this technique you can create really directory-independent extensions.

16 1
7 followers
Viewed: 16 888 times
Version: Unknown (update)
Category: Tips
Written by: GOsha
Last updated by: GOsha
Created on: Nov 19, 2010
Last updated: 13 years ago
Update Article

Revisions

View all history

Related Articles