Yii::import() and Extensions


I’m writing an extension that is made up of a few different class files, with a subdirectory or two.

From what I’ve seen of other extensions, they use Yii::import(), and specify the full path to whatever class file they want to load, eg. Yii::import(‘ext.yii-ext.authorname.myspecialsnowflake.behaviors.ClassNameHere’);

Trying to move these extensions out of their ridiculous directories into the root of extensions/ (or grouping them into extensions/behaviors/, for example) breaks everything, because Yii::import() is effectively a require() with absolute pathing.

I want to avoid this shtick with my own extension.

What’s the recommended way to import a class using a relative path, instead of the full ext.foo.bar absolute path?

(Require()? Have I missed something with Yii::import()?)

Edit: Damn, I think I should’ve posted this in Tips, Snippets and Tutorials. Could a mod move this, please? (Sorry.)

Edit #2: Thanks for the move. :)

Tips, snippets and tutorials is just like the title say for posting tips… tutorials…

You are asking a question so a proper forum is "general discussion for Yii 1.1.x"

I think you can first define a path alias for your extension using setPathOfAlias and then do imports:

Yii::setPathOfAlias('myalias', dirname(__FILE__));



The simpler way is to use require() of course, but maybe it’s not that flexible.