yii-user Extension “include(UserModule.php): failed to open stream” Error

Creating a new (Yii) controller and implementing access control for it with the yii-user extension, I got this PHP warning/error today:

include(UserModule.php): failed to open stream: No such file or directory

Screenshot of yii-user extension warning.

Screenshot of yii-user extension warning.

In the installation instructions for the yii-user extension, one is instructed to modify the main yiiframework configuration file: main.php, and to add the following 2 lines to it… just like this (see line numbers 7 & 8 below):

return array(
    #...
    // autoloading model and component classes
    'import'=>array(
        'application.models.*',
        'application.components.*',
        'application.modules.user.models.*',
        'application.modules.user.components.*',
    ),
    #...

Everything worked very well for a while but when I created a new controller for my web site recently, I started getting the error described in this article.

I didn’t notice it right away but the (failing) included file UserModule.php was actually a file that exists under the modules/user/ folder; not under modules/user/models/ or modules/user/components/, both folders newly defined in my configuration file!

The fix, at least for me, was to simply insert the parent folder in my main.php configuration file – like this:

return array(
    #...
    // autoloading model and component classes
    'import'=>array(
        'application.models.*',
        'application.components.*',
        'application.modules.user.*',
        'application.modules.user.models.*',
        'application.modules.user.components.*',
    ),
    #...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>