Search code examples
phpyiiyii-extensionsyii-modules

Yii modules not working on my site


I have a website powered by yii framework.

Yii Version: 1.1.14

Php version: above 5.4

I tried to install a forum module from the following location

http://www.yiiframework.com/extension/bbii

I added the modules in the main.php as specified in the readme file. But the /forum is not working and I tried some other modules and none of them are working on my installation. I am stuck at the moment and I tried google but it is like a unique error and I don't know how to debug it. Please help. Thanks

return array(
        'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
        'name'=>'testapp',
        'preload'=>array('log','bootstrap'),
        'import'=>array(
            'application.models.*',
            'application.components.*',
            'application.vendor.*',
            'application.controllers.NavSort*',
            ),
        'modules'=>array(
            'gii'=>array(
                'class'=>'system.gii.GiiModule',
                'password'=>'123',
                // If removed, Gii defaults to localhost only. Edit carefully to taste.
                'ipFilters'=>array('127.0.0.1','::1'),
                'generatorPaths' => array(
                        'bootstrap.gii'
                    ),
                ),
            'forum'=>array(
                'class'=>'application.modules.bbii.BbiiModule',
                'adminId'=>1,
                'userClass'=>'User',
                'userIdColumn'=>'id',
                'userNameColumn'=>'username',
                ),
            ),
        'homeUrl'=>array('site/login'),
        // application components
        'components'=>array(
            'bootstrap' => array(
                'class' => 'ext.yiibooster.components.Bootstrap',
                ),
            'user'=>array(
                // enable cookie-based authentication
                'allowAutoLogin'=>true,
                ),          
            'session'=>array(
                'autoStart'=>true,
                'sessionName'=>'session',
                'cookieMode' => 'only',
                'timeout'=>86400,
                ),
            'urlManager'=>array(
                'urlFormat'=>'path',
                'showScriptName'=>false,
                //'urlSuffix'=>'.html',
                'urlSuffix'=>'',
                'class' => 'UrlManager',
                'rules'=>array(
                    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                    '<controller:[\w\-]+>/<action:[\w\-]+>' => '<controller>/<action>',
                     // defaults to a site page if not above
                    '<view:[a-zA-Z0-9-]+>/'=>'site/login',
                    ),
                ),
            'db'=>array(
                'connectionString' => 'pgsql:host=localhost;port=5432;dbname=testdb',
                'emulatePrepare' => false,
                'username' => 'postgres',
                'password' => 'root', 
                //'tablePrefix'=>'',
                'charset' => 'utf8',
                ),
            'errorHandler'=>array(
                'errorAction'=>'site/error',
                ),
            'log'=>array(
                'class'=>'CLogRouter',
                'routes'=>array(
                    array(
                        'class'=>'CFileLogRoute',
                        'levels'=>'error, warning',
                        ),
                    ),
                ),
            ),
        'params'=>array(
            // this is used in contact page
            'adminEmail'=>'[email protected]',
            ),
        );

Solution

  • You are missing URL rules that would direct framework into opening a module.

    You can use both universal rules

    '<module:\w+>/<controller:\w+>/<action:[\w-]+>' => '<module>/<controller>/<action>',
    '<module:\w+>/<controller:\w+>'                 => '<module>/<controller>',
    '<module:\w+>'                                  => '<module>',
    

    Or you can create specific rules

    'forum/<controller:\w+>/<action:[\w-]+>'        => 'forum/<controller>/<action>',
    'forum/<controller:\w+>'                        => 'forum/<controller>',
    'forum'                                         => 'forum',
    

    The difference is only when universal rules conflict with other rules, then you should use more specific ones.

    For example, to make Gii in my application work correctly with my multi-language system, I use following rule

    'gii/<controller:\w+>/<action:[\w-]+>'          => 'gii/<controller>/<action>',
    

    And remember, it matters, where you position your URL rules in that array. First one that will match, will trigger opening that specific action. Read more about URL Management.