saladha
(Sajeewanie2009)
1
hi I used to handle the error in yii getError().I need to set it in the flash.
this is my contrallor code
Yii::app()->user->setFlash('Error',serialize($usermodel->getErrors()));
to convert array to string I used serialize().
this is my view
<?php
foreach(Yii::app()->user->getFlashes() as $key => $message)
echo '<div id="display-success">' . $message . "</div>\n";
}
?>
bt it gives
a:1:{s:14:"preferred_name";a:1:{i:0;s:31:"Preferred Name cannot be blank.";}}
can I get only the message without others
I mean I need to display only
"Preferred Name cannot be blank."
pls tell How Do I do that.
thanx in advance
saladha
(Sajeewanie2009)
2
Or else is there a way to do it .pls help me with example code
Hi,
May be you can split like this… and send only errors not serialize content…
I hope this will solve your problem
$errors = array();
foreach ($authItem->getErrors() as $attribute=>$attributeErrors)
foreach ($attributeErrors as $error)
$errors[] = array(
'attribute'=>$attribute,
'label'=>$authItem->getAttributeLabel($attribute),
'error'=>$error
);
$response = compact('errors');
}
header('Content-type: application/json');
echo CJSON::encode($response);