Yii Framework Forum: Handle Errors - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Handle Errors Rate Topic: -----

#1 User is offline   sldra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 123
  • Joined: 11-October 12

Posted 15 October 2013 - 07:47 PM

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
0

#2 User is offline   sldra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 123
  • Joined: 11-October 12

Posted 15 October 2013 - 08:12 PM

Or else is there a way to do it .pls help me with example code
0

#3 User is offline   chandran 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 494
  • Joined: 08-October 12
  • Location:Austria

Posted 16 October 2013 - 03:09 AM

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);
Thanks
chandran nepolean

My own extension:
http://www.yiiframew...sion/ejqueryte/

My wiki
http://www.yiiframew...checkboxcolumn/

If it work dont hesitate to click +1 button
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users