Yii Framework Forum: Test Database Connection - Yii Framework Forum

Jump to content

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

Test Database Connection Rate Topic: -----

#1 User is offline   Stephen51 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 61
  • Joined: 09-May 12

Posted 23 July 2013 - 03:50 PM

I am trying to create a controller action that will test a user-defined database connection. I am calling this controller action with ajax. My problem is that if the database connection fails, it throws an Exception (which is handled by Yii) and the message returned to the user is ugly. Instead, I want to use my own controller action to display a nice message to the user. Is there a way to do this?
0

#2 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,335
  • Joined: 21-February 11
  • Location:Greece

Posted 23 July 2013 - 05:27 PM

Hi

1) you could modify the protected/views/site/error.php to display what you want
2) if you want to redirect to another error file on the fly (before error occurs) you could use this

Yii::app()->setComponents(array(
    'errorHandler'=>array(
        'errorAction'=>'/anotherfolder/yourerror'
    )
));

Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   Stephen51 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 61
  • Joined: 09-May 12

Posted 23 July 2013 - 06:08 PM

Thanks! Does this work for Ajax? When I try it out, it does not go to the controller action specified by errorAction. It appears that CApplication::displayError() is being called on Ajax requests, which is preventing the controller action from being called. See line 284 in class CErrorHandler Yii v1.1.13.
0

#4 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,335
  • Joined: 21-February 11
  • Location:Greece

Posted 23 July 2013 - 09:54 PM

View PostStephen51, on 23 July 2013 - 06:08 PM, said:

Thanks! Does this work for Ajax? When I try it out, it does not go to the controller action specified by errorAction. It appears that CApplication::displayError() is being called on Ajax requests, which is preventing the controller action from being called. See line 284 in class CErrorHandler Yii v1.1.13.



if you check the default eroor action you will see in ajax request case that only the message return rather that entire layout, so you have to do the same.

public function actionError() {
        if ($error = Yii::app()->errorHandler->error) {
            if (Yii::app()->request->isAjaxRequest)
                echo $error['message'];
            else
                $this->render('error', $error);
        }
    }

Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#5 User is offline   Stephen51 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 61
  • Joined: 09-May 12

Posted 31 July 2013 - 03:49 PM

That works. Appreciate your help.
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