You are viewing revision #3 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.
How to implement directory independent extensions ¶
Many people want to use downloaded extensions in their own way. As for me the most of the extensions are require me to correct Yii::import() inside their source code. All these extensions are directory dependent. To avoid a situation described 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 another 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 a really directory-independent extension.
Include in Yii core
Brilliant!!
Perhaps Yii::import could be modified to include this feature
Something like
public static function import($alias,$forceInclude=false,$baseDir='') { if($baseDir) $alias=md5($dir).".$alias"; // Current Yii::import code }
then extensions can import with
Yii::import('Class',false,dirname(__FILE__));
Correct code
Dohhh!!
public static function import($alias,$forceInclude=false,$baseDir='') { if($baseDir) { $pathAlias=md5($dir); Yii::setPathOfAlias($pathAlias,$baseDir); $alias="pathAlias.$alias"; } // Current Yii::import code }
@Yeti
I think there is no need to modify
Yii::import()
. You can write simple helper to yii.If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.