BaseActiveRecord with print_r()

Hi community,

I have some question regarding assigning values from array to object.

After assigning value from array to object…i tried to print the object

it gave me below output. it s really magic… i dont know how it return array values as Xml …any guess or any help?

common\models\PhoPerson Object ( [_attributes:yii\db\BaseActiveRecord:private] => Array ( [person_pho_id] => SimpleXMLElement Object ( [0] => C859ED75EDF4EEE4 ) [person_vname] => SimpleXMLElement Object ( [0] => chandran ) [person_fname] => SimpleXMLElement Object ( [0] => Nepolean ) [person_title] => SimpleXMLElement Object ( [0] => BE ) [person_email] => SimpleXMLElement Object ( [0] => chandran@aoe.at ) [person_role] => SimpleXMLElement Object ( [0] => LB ) [person_roledesc] => SimpleXMLElement Object ( [0] => programming ) [person_offtel] => SimpleXMLElement Object ( ) [person_picturl] => [person_infourl] => SimpleXMLElement Object ( [0] => https://www.online.a…d=DEFDDEDF4EEE4 ) ) [_oldAttributes:yii\db\BaseActiveRecord:private] => [_related:yii\db\BaseActiveRecord:private] => Array ( ) [_errors:yii\base\Model:private] => [_validators:yii\base\Model:private] => [_scenario:yii\base\Model:private] => default [_events:yii\base\Component:private] => Array ( ) [_behaviors:yii\base\Component:private] => Array ( ) )

Because of this i am getting validation error …

all fields (person_vname,person_fname and etc[size="2"]) should be string… I can see what is the problem… because it is [/size]SimpleXMLElement object…

I dont know how to solve this problem… anybody faced same kind of problem.?

What did you do? From what array? To ActiveRecord object?

Hi thanks for your reply.

To be more clear…i will paste my other code

In below code $res array is filled after parsing xml and i am filling array





$xml = new SimpleXMLElement($uri,null,TRUE);

		$xml = new SimpleXMLElement($xml->asXML());

		$resss=$xml->xpath('//person');

foreach($resss as $ress){

				$res["personID"] = $ress->personID;

}

Next step is i am creating new person model and passing to method getEmployeeObject with new object and filled array





$nmodel = new PhoPerson;

$nmodel = $this->getEmployeeObject($res, $nmodel);// after object filled with array values i am calling save..    

$nmodel->save();  --> here i am facing problem..i am getting validation error..all values should be string



Third step is filling value of model from array to model





private function getEmployeeObject($res,$model){

		$model->person_pho_id = $res["personID"];

		$model->person_vname = $res["p_vname"];

		$model->person_fname = $res["p_fname"];

		

		return $model;

	}

I hope i have explained what i am trying to achieve…just assign object value from array and save it… thats all

If $res["personID"] is a SimpleXMLElement object, then $model->person_pho_id will also be a SimpleXMLElement object.

Hi ,

Thanks i have solved my problem by using

$model->person_pho_id = strval($res["personID"]);