Error handling in modules

I have a module in my yii webapp

When there is an error in the module, i’d like it to be handled by global error handler.

In /protected/config/main.php I have the following setting:




I’ve also tried


If, for example, there is an exception in my webapp’s controller the error handlers work fine.

But those are not working for module: it still searches error handler inside the module.

How should I specify error handler really global to make it global even for modules?

That is actually strange.

I just tried to create a module in another app and put an exception there.

And it worked just fine.

Will try to figure out what’s the problem.

If someone ever faced the same problem, then I’ll apreciate your advise

I figured out a little more detailes about my problem.

  1. I changed default controller to ‘index’ in the main app.

  2. No matter what default controller (‘index’ or ‘default’) I use the problem occurs in the module anyway

  3. If I go to default/index (where exception is thrown) then the exception is handler by main app’s errorHandler

  4. But if I go to index/index (where exception is also thrown) then I get something like


The system is unable to find the requested action "error". (D:\projects\test\framework\web\CController.php:444)

#0 D:\projects\test\framework\web\CController.php(262): CController->missingAction('error')

#1 D:\projects\test\framework\web\CWebApplication.php(328): CController->run('error')

#2 D:\projects\test\framework\base\CErrorHandler.php(279): CWebApplication->runController('index/error')

#3 D:\projects\test\framework\base\CErrorHandler.php(178): CErrorHandler->render('error', Array)

#4 D:\projects\test\framework\base\CErrorHandler.php(103): CErrorHandler->handleException(Object(CHttpException))

#5 D:\projects\test\framework\base\CApplication.php(631): CErrorHandler->handle(Object(CExceptionEvent))

#6 [internal function]: CApplication::handleException(Object(CHttpException))

#7 {main}

Well, I spent half night to localize the problem.

And here is my resolution:

If module’s controller has the same name as main app’s default controller

then throwing exception in the module will cause the call of module’s error handler

instead of app’s one.

And in case if module has no error handler we will get an error.

Let me know, if I’m doing something wrong. And let me know how to do it the right way?

Can someone of framework developers give any comment about it?

I provided detailed description of my problem and it seems to be a bug in yii.

But still no reply…

A class can only be declared once at runtime - otherwise PHP will throw a fatal error. Means if Yii would first include /modules/foo/controllers/SiteController.php and then /controllers/SiteController.php a fatal error would be thrown because the class "SiteController" were already declared in the modules controller file. Before Yii does include a controller file, it does check whether the correspondending class was already declared (which is true in your case).

You may change the name of the controller in the module to something else.

In Yii 2 this will be "fixed" by using namespaces.


thank you for explanation.

Will await for Yii 2.0 and find other ways to implement what I want.