首页 > 解决方案 > 获取模块配置设置或参数

问题描述

我正在使用 Yii 1,并试图让我的模块设置config/main.php看起来像这样

'modules' => array (
                'products' => array(
                    'countries' => array('sg', 'th'),
                 )
),

此代码适用于我的非products控制器

Yii::app()->controller->getModule('Products')->countries;

但是当我添加到我的自定义 URL 类中时,它不会。这是我课的一部分

class RegionUrlRule extends CBaseUrlRule
{
    public $connectionID = 'db';

    private $countryArray;

    
    public function __construct() {

        //get list of allowed countries
        $this->countryArray = Yii::app()->controller->getModule('Products')->countries;
    }
    
    public function createUrl($manager,$route,$params,$ampersand)
    {
        .........
    }

    .........

}

对此,我收到此错误

Call to a member function getModule() on null 

当我使用这个

Yii::app()->getModule('Products')->countries;

我什么也没得到,也没有错误

我该如何解决?谢谢

标签: phpyiiyii1.x

解决方案


推荐阅读