Yii Framework Forum: [Solved] Cdbexception Not Being Rendered In View - Yii Framework Forum

Jump to content

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

[Solved] Cdbexception Not Being Rendered In View Rate Topic: -----

#1 User is offline   Anthony Gough 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 29-October 12

Posted 04 December 2012 - 08:19 PM

I have a constraint on a field in a table that the particular field must be unique. If I try and create a new client and use an id that is not unique I generate a CDbException error. I would like this error to be gracefully handled by a view rather than the getting "CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation:.....etc" being written to the browser.
In my main config file I have:
'components'=>array(
         'errorHandler'=>array(
			// use 'site/error' action to display errors
			'errorAction'=>'site/error',


In my sitecontroller is
public function actionError()
	{
		if($error=Yii::app()->errorHandler->error)
		{
			if ( CDbException == $error->type) {
           		$this->redirect(array("site/error")); }
			else if(Yii::app()->request->isAjaxRequest) {
				echo $error['message']; }
			else
				$this->render('error', $error);
		}
	}


And I have a view in the ..views\site\error.php

How can I have the error displayed in a view rather than the CDbException being written straight to the browser?
0

#2 User is offline   Anthony Gough 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 52
  • Joined: 29-October 12

Posted 04 December 2012 - 08:58 PM

Solved - Need to remove the YII_DEBUG code in index.php
1

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