Pathik Vejani
Pathik Vejani

Reputation: 4491

how to setup second module in yii

I have configured yii on localhost with one module name as admin.
Now i have to add another module with name store.

in main.php i have:

'import' => array(
        'application.models.*',
        'application.components.*',
        'application.modules.*',
        'application.modules.admin.models.*',
        'application.modules.store.*',
        'application.modules.store.components.*',
        'application.modules.store.models.*',
        'ext.yii-mail.YiiMailMessage',
        'application.extensions.EAjaxUpload.*',
        'bootstrap.helpers.*',
        'bootstrap.widgets.*',
        'bootstrap.components.*',
        'ext.EPhpThumb.EPhpThumb',
        ),
'modules' => array( 
        'gii' => array(
            'class' => 'system.gii.GiiModule',
            'password' => 'abcd11', 
            'ipFilters' => array('127.0.0.1', '::1'),
            ),
        'admin' => array('defaultController' => 'admin'),
        'store' => array( 'debug' => true ),
        ),
// application components
    'components' => array(
        'request' => array( 
            ),
        'ePdf' => array(
            'class' => 'ext.yii-pdf.EYiiPdf',
            'params' => array(
                'mpdf' => array(
                    'librarySourcePath' => 'application.vendors.mpdf.*',
                    'constants' => array(
                        '_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
                        ),
                    'class' => 'mpdf', // the literal class filename to be loaded from the vendors folder

                    ),
                ),
            ),
        'bootstrap' => array(
            'class' => 'bootstrap.components.TbApi', // bootstrap configuration
            ),
        'yiiwheels' => array(
            'class' => 'yiiwheels.YiiWheels', // yiiwheels configuration
            ),
        'phpThumb' => array(
            'class' => 'ext.EPhpThumb.EPhpThumb',
            ),
        'session' => array(
            'timeout' => 86400,
            ),
        'user' => array(
            'loginUrl' => array('admin/login'),
            // enable cookie-based authentication
            'allowAutoLogin' => true,
            'autoRenewCookie' => true,
            'identityCookie' => array('domain' => 'http://localhost'),
            'authTimeout' => 86400,
            ),
        // uncomment the following to enable URLs in path-format
        'mail' => array(
            'class' => 'ext.yii-mail.YiiMail',
            'transportType' => 'smtp',
            'transportOptions' => array(
                'host' => 'localhost',
                'username' => '',
                'password' => '',
                'port' => '25',
                ),
            'viewPath' => 'application.views.mail',
            ),
        'urlManager' => array(
            'urlFormat' => 'path',
            'showScriptName' => false,
            'caseSensitive' => false,
            'rules' => array(
                '/' => 'admin/',
                'page/<id:[0-9]+>/' => 'page/publicPage',
                'page/<slug:[a-zA-Z0-9-_\/]+>/' => 'page/view',
                'admin' => 'admin/login',
                '<slug:' . SLUG_CONTACT_US . '>' => 'page/contact',
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
                ),
            ),
        // uncomment the following to use a MySQL database
        'db' => array(
            'connectionString' => 'mysql:host=localhost;dbname=' . $arrConfig['dbName'],
            'emulatePrepare' => true,
            'username' => $arrConfig['dbUser'],
            'password' => $arrConfig['dbPass'],
            'charset' => 'utf8',
            ),
        'errorHandler' => array(
            // use 'site/error' action to display errors
            'errorAction' => '/admin/dashboard/error',
            ),
        'log' => array(
            'class' => 'CLogRouter',
            'routes' => array(
                array(
                    'class' => 'CFileLogRoute',
                    'levels' => 'error, warning',
                    ),
                ),
            ),
        'hybridAuth' => array(
            'class' => 'ext.widgets.hybridAuth.CHybridAuth',
            'enabled' => true, // enable or disable this component
            'config' => array(
                "base_url" => $siteUrl . '/hybridauth/endpoint',
                "providers" => array(
                    "Google" => array(
                        "enabled" => false,
                        "keys" => array("id" => "", "secret" => ""),
                        ),
                    ),
                "debug_mode" => false,
                "debug_file" => "",
                ),
        ), //end hybridAuth
        ),


can anyone help?
if any other information is need then i will edit my question.

Upvotes: 1

Views: 123

Answers (2)

cn0047
cn0047

Reputation: 17071

To add module you just need to add it name to modules main config.
Then you should add to urlManager rule like '/store' => 'store/guest/index', after it controller guest/index in module store will be work.

At directory protected you should have:

1) protected/modules/store/StoreModule.php

<?php
class StoreModule extends CWebModule
{
}

2) protected/modules/store/controllers/guest/IndexController.php

<?php
class IndexController extends CController
{
    public function actionIndex()
    {
        var_dump(200);
    }
}

Example:

1) Create new yii app: php yiic.php webapp testdrive.
2) Apply diff.
3) Run app: php -S localhost:8002 index.php.
4) Check: curl http://localhost:8002/store
5) Add module admin. Apply diff.
6) Check: curl http://localhost:8002/admin

Upvotes: 1

Ary Wibowo
Ary Wibowo

Reputation: 539

it because your app doesn't know which module to load. you need to set class that refer to class of module that you want to load. example :

'modules' => [
    'admin' => [
        'class' => 'app\modules\admin\Module',
        'defaultController' => 'admin'
    ],
    'gii' => [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.*.*'],
    ],
],

Upvotes: 1

Related Questions