Yii Framework Forum: Getmodule - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Getmodule find the current module property Rate Topic: -----

#1 User is offline   firefly 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 21-May 12

Posted 01 February 2013 - 06:30 AM

Hello everybody,

I found out the if you are in the init function of a module and you call Yii::app()->getModule('moduleName')->property; the application will enter into an infinite loop.

for example:

class moduleName extends CWebModule
{
   public property = 1;
   public function init()
    {
 		Yii::app()->getModule('moduleName')->property; // infinite loop; 
   }
}



So how can I find out the property value?

 $this->property; 




is not good, because I what tho be able to use the code in other parts of the application;

for example:



class Component{
	public static function moduleProperty(){
		return Yii::app()->getModule('moduleName')->property;
        } 

}






class moduleName extends CWebModule
{
   public property = 1;

   public function init()
   {
      Component::moduleProperty();
   }
}

0

#2 User is offline   firefly 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 21-May 12

Posted 01 February 2013 - 06:35 AM

haha, I fount the solution:


class Component{
        public static function moduleProperty($module){
                return $module->property;
        } 

}




class moduleName extends CWebModule
{
   public property = 1;

   public function init()
   {
      Component::moduleProperty($this);
   }
}



Well in the lates yii version: yii-1.1.13.e9e4a0 the infinit loop still persist even with the above changes..

Is there any way to aviod this infinit loop? Maybe it is a bug or something...
0

#3 User is offline   firefly 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 21-May 12

Posted 05 March 2013 - 08:04 AM

Anyone???
0

#4 User is offline   acorncom 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 100
  • Joined: 25-February 11
  • Location:CO, USA

Posted 05 March 2013 - 08:21 AM

What happens of you just do $this->property? Can you just pass that variable directly to your component?
0

#5 User is offline   firefly 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 21-May 12

Posted 05 March 2013 - 08:39 AM

View Postfr0d0z, on 05 March 2013 - 08:21 AM, said:

What happens of you just do $this->property? Can you just pass that variable directly to your component?


Basically in a module init function, I can not access $this->property because; the script just seems to enter into an infinite loop...



0

#6 User is offline   acorncom 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 100
  • Joined: 25-February 11
  • Location:CO, USA

Posted 05 March 2013 - 09:54 AM

Does that occur if you try it set config values for your module? I've got some modules that I add in submodules to and things work fine. The syntax is like this:

$this->modules = array(
    ... config information for other modules here
);


I know that code works, as it's running in production on a system that launched yesterday.

Let me know. Also, you don't happen to be overriding your __get / __set methods, so you?
0

#7 User is offline   xicond 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 06-October 12

Posted 26 June 2013 - 09:02 PM

Hi all,
Is the getModule mechanism, can acquired the nested module?

Thanx in advance
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users