Changing The Model Post Name In Forms Cactiveform And Children Of Cmodel

i’m a beginner to yii.

i could find my way as below. But my question is :

Is there any other solution to set a post name for a particular model? for example set an alias post name inside the model? or even use different post names for one form model? because we do the massive assignment by hand in the action method.

Thanks in advance

Today when i saw my long namespaced model had been converted to some thing like this in the $_POST :

Site_models_User

i tried to find a solution to make an alias for it within Yii form system.

There are different discussions i could find :

[Enhancment] Allow model to change the name used on forms :

https ://github.com/yiisoft/yii/issues/470

change resolveName and getIdByName to replace namespce "\"

https ://github.com/yiisoft/yii/pull/2225

Rework of #2225

https ://github.com/yiisoft/yii/pull/2446

However i couldn’t find a final explaination to resolve this stuff but the final solution i could find was :

we must implement a model name converter to have different names for all models in postback(for example shortening the names of all models) :


CHtml::setModelNameConverter(function ($mixedModel){	//mixedModel may be string or model obj

	//retrieve, convert the name of model class and return the name you would like to use for it

});

//later , below static method will use our converter


CHtml::modelName()

//to reset the converter pass null into the ::setModelNameConverter

i wrote the converter in the module event method "beforeControllerAction"


	public function beforeControllerAction($controller, $action) {

		if (parent::beforeControllerAction($controller, $action)) {

			// this method is called before any module controller action is performed

			// you may place customized code here

			\CHtml::setModelNameConverter(function ($mixedModel) {

						$mixedModel = is_object($mixedModel) ? get_class($mixedModel) : strval($mixedModel);

						if (!$mixedModel)

							throw new \CException("No valid model has been passed into Converter");

						return trim(str_replace(array('\Site\models\\', 'Site\models\\', '\\'), array('', '', '_'), $mixedModel), '_');

					});

			return true;

		}

	}

i hope this to be useful for some friends.

Masters , is there any other solution to set one or multiple especial alias(es) for a particular model and i don’t know?

Tnx in advance

Ow , excuse me the answer was totally clear.

If the model object is passing inside the converter so i can choose any name for post name via one of the properties of the model even based on the SCENARIO easily.