Problem when call parent::__construct in AR subclass

Hi:

I have this AR class:




class Empleado extends CActiveRecord

{

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


        public function __construct($scenario='insert'){

            //do something interesting...

            parent::__construct();

            }



The parent::__construct() in my subclass is causing an infinite recursion due to CActiveRecord internally instantiates my Empleado class so my stack error looks like that:




5	0.2004	5928056	CActiveDataProvider->__construct( )	..\EmpleadoController.php:130

16	0.2004	5928176	CActiveRecord::model( )	..\CActiveDataProvider.php:75

17	0.2034	5976920	Empleado->__construct( )	..\CActiveRecord.php:387

18	0.2035	5976920	CActiveRecord->__construct( )	..\Empleado.php:24

19	0.2035	5977000	CActiveRecord->getMetaData( )	..\CActiveRecord.php:78

20	0.2035	5977056	CActiveRecord::model( )	..\CActiveRecord.php:403

21	0.2035	5978056	Empleado->__construct( )	..\CActiveRecord.php:387

22	0.2035	5978056	CActiveRecord->__construct( )	..\Empleado.php:24

23	0.2035	5978136	CActiveRecord->getMetaData( )

...



This means that I can’t override __construct() in AR subclasses and allways should use afterConstruct() ?

Cheers

Sebastian

Dear Friend,

Can you please try this.




class Empleado extends CActiveRecord

{

        public static function model($className=__CLASS__)

        {

                return parent::model($className);

        }


        public function __construct($scenario='insert'){

            

            parent::__construct($scenario);

            //do something interesting...


            }



I think it stops instantiation of object, when constructed without parameters.

I am not sure of what exactly the problems are.I need further inputs on this.

Regards.

Hi seenivasan:

Works perfectly!

I don’t see exactly why but I’m new to yii and PHP too so maybe I’m loosing something in the way :)

Many thanks!

Cheers

Sebastian