Hi Guys,
I have come across a behaviour in yii which does not sound right. I have been trying to test the Yii::createComponent method to see if it can handle class name ambiguity. In this case assume we have a class named Partners located in two different directories with the same method names inside which return different values. The problem is that I still end up getting the same results from one class.
Looks like the file is auto loaded once and overrides the second one meaning that the match is done by name and not by path. Below is a simple test case.
/controllers/PlayGroundController.php
class PlayGroundController extends Controller {
public function actionLaunch(){
$instance = new PlayGround();
echo $instance->showMeInner() . " <br> " . $instance->showMeOutter();
}
}
/libraries/PlayGround.php
class PlayGround {
/**
* This calls the function in the main application path in the
* protected/models
*/
public function showMeOutter(){
$objx = Yii::createComponent('application.models.Partners');
return $objx->test();
}
/**
* This calls the function in the partners model in the customers module
*/
public function showMeInner(){
$objy = Yii::createComponent('application.modules.customers.models.Partners');
return $objy->test();
}
}
/application/models/Partners.php
class Partners extends CActiveRecord
{
public function test(){
return "Hello Earthling.....I am from outer space";
}
}
/application/modules/customers/models/Partners.php
class Partners extends CActiveRecord
{
public function test(){
return "I come in peace.....I am from inner space";
}
}
From the above sample code running /host/playground/launch the expected output would be:
I come in peace.....I am from inner space
Hello Earthling.....I am from outer space
But I am getting:
I come in peace.....I am from inner space
I come in peace.....I am from inner space
I’m I doing anything wrong ? Any help is highly appreciated.