【问题标题】:how to setup second module in yii如何在 yii 中设置第二个模块
【发布时间】:2016-12-09 01:50:33
【问题描述】:

我已经在 localhost 上配置了 yii,一个模块名称为 admin
现在我必须添加另一个名称为 store 的模块 .

在 main.php 我有:

'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
        ),


谁能帮忙?
如果需要任何其他信息,我会编辑我的问题。

【问题讨论】:

  • 还有哪些文件需要修改?

标签: php yii module architecture


【解决方案1】:

这是因为您的应用不知道要加载哪个模块。您需要设置 class 来引用您要加载的模块类。示例:

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

【讨论】:

【解决方案2】:

要添加模块,您只需将其名称添加到模块主配置。
然后你应该在模块store中的控制器guest/index之后添加到urlManager规则,如'/store' =&gt; 'store/guest/index',

在目录protected 你应该有:

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);
    }
}

例子:

1) 创建新的 yii 应用: php yiic.php webapp testdrive
2) 申请diff
3) 运行应用程序:php -S localhost:8002 index.php
4) 检查:curl http://localhost:8002/store
5) 添加模块管理员。申请diff
6) 检查:curl http://localhost:8002/admin

【讨论】:

  • 现在在我的 urlmanager 中:'rules' => array('/' => 'admin/', 'page//' => 'page /publicPage', 'page//' => 'page/view', 'admin' => 'admin/login', '' => '页面/联系人', '/' => '/view', '//' => '/', '/' => '/' , ),
  • guest - 这是你的控制器的路径。
  • 你应该添加:'/store' =&gt; 'store/guest/index',
  • 我添加了这个:'store' => 'store/login',
  • 但出现错误:注意:未定义的变量:模型在 C:\xampp\htdocs\yii\protected\modules\admin\controllers\DashboardController.php 第 455 行
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多