Pass Constructor Parameters To New Component

Hi

I want to pass a variable to my extension but directly to the contructor




Yii::app()->setComponents(array('mycomponent' => array(

                'class' => 'ext.myext.myextfile',

                'varToConstructor' => Yii::app()->db, //of course not works on contructor but on init

        )));

My extension extends a class of yii that has a constructor with argument parameter the database component.

How to achieve that?

Thanks!

Notes: The method createComponent of Yiibase pass to contructor only if func_num_args is creater than 1.




Yii::app()->setComponents(array(

  array('myComponent' => new Component(Yii::app()->db))

));



Thanks for reply but dosen’t work

Anyone please ?

It’s tricky so it’s better to have db connection as setter or public class member.

Hi samdark

My extension extends a core Yii class that has a private member variable. and the setting take place in contructor.

So I cannot make it public or create a setter for this variable.

The only way to do that is copy the core file into my extension and change the

private to protected (or public) or hack Yii core file but I would to avoid it.

I have similar issue on this topic

http://www.yiiframework.com/forum/index.php/topic/45444-cviewaction-protected-viewpath/page__p__214573__fromsearch__1#entry214573