Do Some Treatment Before Error Handling

Hello to Yii Community.

I have a big yii application where I have a lot of profile artists : myapp.com/artist/profile/{myprofile}. I want that when a user type a wrong URL for example: myapp.com/{myprofile} , I will automatically redirect to the myapp.com/artist/profile/{myprofile}.

All this is done by the smartsuggest() function which is executed in the site/error action.

My problem is that I always have a logfile that which contain all the profile redirection .

Logically I didn’t get a 404 error so I don’t want to have this in my log file.

How can I avoid the error in the log file without going to each


throw new CHttpException

and add before, the smartsuggest() function?

Thanks for any one which can help me.

Hi all,

Anyone have an idea?

I just want to handle the 404 error before it throw the exception, made some treatment to redirect the user to other link or suggest some pages. That’s why I need to override the runController function of CWebApplication or handleException function of CApplication. I am new with the behaviors and components.

Can you explain this for me?

Thanks a lot in advance.

Put this code in site’s default error action. Mine is site/error


public function actionError() {

       

        $error = Yii::app()->errorHandler->error;

        

        if (isset($error)) {

            $id = Yii::app()->user->id;


            if ($error['code'] == 404 || $error['code'] == 403) {

                $this->redirect('/user/profile/' . $id);

                die;

            }

            if ($error['code'] == 500) {

                $this->redirect('/user/profile/' . $id);

            }

        }

    }

Hi hemc,

Thanks for the reply.

That’s what I’ve done. But I want to avoid any error in my logs file or Email Logs Route.

I want to redirect the request before it generate any error. That’s why I need to override the HandleRequest or runController function.

Any idea?

Thanks again.

I solved my problem by following acorncom’s post: http://www.yiiframework.com/forum/index.php/topic/31398-add-a-404-event-to-cwebapplication-runcontroller/page__view__findpost__p__234000

Thank your acorncom