adding manual data for attributes model manualy

hello guys . im soory im asking again …

i had this trouble since this morning …

i want to save an array into a model that i get from multiple field




if(isset($_POST['komponent'])){

                    //print_r($_POST['komponent']);    [i]//  [0] => a [1] => b [/i]

                    $mod = array("komponent" => $_POST['komponent']);

                    print_r($mod);   [i]//Array ( [komponent] => Array ( [0] => a [1] => b ) ) [/i]

                    $modelb->attributes= $mod;

                    $modelb->save();

                }

i tried to input this with an array into field named komponent

i had tried to save with more declare in model like this


$modelb->attributes['komponent'] = $mod;

when i see in database my field fulled with "array" not the data i tried to store …

oh yea . i had tried this one too …

i thougt when looping it will store manualy one by one


if(isset($_POST['komponent'])){

                    print_r($_POST['komponent']);

                    foreach ($_POST['komponent'] as $newkomponent):

                        

                        $baru = array('komponent'=>$newkomponent);

                     

                        $modelb->attributes = $baru;

                        $modelb->save();

                        

                    endforeach;

                    print_r($baru); 

                    

                

need you`r help :)

Take a look


public function setAttributes($values,$safeOnly=true)

	{

		if(!is_array($values))

			return;

		$attributes=array_flip($safeOnly ? $this->getSafeAttributeNames() : $this->attributeNames());

		foreach($values as $name=>$value)

		{

			if(isset($attributes[$name]))

				$this->$name=$value;

			else if($safeOnly)

				$this->onUnsafeAttribute($name,$value);

		}

	}

framework checks if the model has such attribute


isset($attributes[$name])

then it sets the value


$this->$name=$value;

then have a look your output


[i]//Array ( [komponent] => Array ( [0] => a [1] => b ) ) [/i]

framework tries to find 0 and 1 attributes from model

then it can not find then does not set value to model.

instead of 0 and 1 here should be attr names.

thanks for your help . i will try to implement this code :)