Scenario and model attributes (AR)

Hi, I have not standart situatuation.

I have 4 scenarios… And in this 4 scenarios I need assigned different attributes, BUT I have some attributes which must assign undependent from scenario value.

As I could see it’s impossible now ? or I wrong ?




if($scenario!=='' && isset($attributes[$scenario]))

       return $this->ensureArray($attributes[$scenario]);



it’s my safeAttr… function




public function safeAttributes()

	{

		return array(

			' username, userpass, retypePass, email, ..... , website',

			'scenario1' => 'anotherAttribute1',

                       'scenario2' => ....



so as I’m right for my purpose I need change it like this ?

code]

public function safeAttributes()

{


	return array(


		' username, userpass, retypePass, email, ..... , website',


		'scenario1' => 'anotherAttribute1, username, userpass, retypePass, email, ..... , website',


                   'scenario2' => 'anotherAttribute2, username, userpass, retypePass, email, ..... , website,


                     ....

[/code]

Maybe I’m wrong but I think what this way is more nicer

when I could write

‘scenario1, scenario2 … ’ => ’ username, userpass, retypePass, email, … , website’,

‘scenario1’ => ‘a1’,

scenario2’ => ‘a2’,

I think it’s more flexibile way

it could be for example:

in CModel.php in 560 line





		foreach ($attributes as $key => $value) {

			$tmo = explode(',', $key);

			if (count($tmo) > 1) {

				// then key consist from more then one scenario name

				foreach ($tmp as $scenarioName) {

					$attributes[$scenarioName] => $value;

				}

				// and finaly we need to remove current pair key value from $attributes

				..

			}

			

		

}

What you think ?

Using this format, you may need to duplicate the same rule for different attributes under different scenarios.

Also, in reality, you won’t have many scenarios.

Now I have registration page with 5 user types (which whey need to choose in this process). Also some fields are appear and disappear, it depends from user choice (user type). But some fields are constant independently from user type choice.

What is why i start this topic.

I agree with what this situation maybe not often (not regular) situation.

Thanks.

You may want to try this. http://www.yiiframework.com/forum/index.php?/topic/3572-form-with-many-optional-fields-meta-scenario-idea/page__p__19325

It allows you to run many scenarios at time, so you can make default scenario for all user types and then 1 scenario for each user type only with fields for that particular user.

I hope it helps.