Accessing the Component in sub-module

Hi all,

I am currently facing one problem about accessing the static array.

The case is that I have sub-modules. Each components directory in sub-modules has Redirector.php in which I am defining the Redirector class.Every Redirector class has $array.

Now the problem is -

I have one class in protected/component and there I want to access $array element of particular module.

I can do it as follows,



But instead of that I want to know is there any other way to use the Redirector class, for eg.

in java to access class Random from sub package we can use java.util.Random without importing the Random class.

i.e. some thing like application.modules.sample.components.Redirector::$array.

Please reply.

Thank You



No this is not possible with PHP.

Maybe you could use a global Redirector class and use that for all modules?

class Redirect


   public static $array = array();


Then in your Module file:

class MyModule extends CWebModule


   public function init()


      Redirector::$array['MyModule']['data'] = array();



But init() in MyModule is only executed when you access the module. So if you need data from all modules (even if they are not initialized yet), you have to load the module first.

Can you explain more? So we could maybe find a better solution.

What you are referring to are namespaces defined by the syntax of the programming language, in this case PHP.

The latest PHP version supports this, but Yii currently does not.

Hi all,

Thank you Y!! and Onman for your valuable responces.

I got one solution. But I wanted to know whether it is good or not.

Actually I was trying to write a generic function in protected/components. And this function needs to get the value from Redirector.php of any sub-module depending on the situation.

So I was needed to have some reference to Redirector class (defined in Redirector.php) of any module in a class defined in protected/components.

To solve this problem

I defined getValue() function in every module class. This function will return the values from Redirector class of respected module.

To access the value in protected/components I used

$value = Yii::app()->getModule($moduleName)->getvalue();

It works fine. But may I know is it the right way ? or is there any other way to do it.

Please Reply.

Thank You.

Prasad Zambare.