简体   繁体   English

无法使用getModule()从模块文件中注册CssFile()

[英]Can't registerCssFile() from module file using getModule()

Instead of calling/registering the CSS in my view. 而不是在我看来调用/注册CSS。 i want to register it in my AbcModule.php since the CSS will be used thru out the module. 我想在我的AbcModule.php注册它,因为将通过模块使用CSS。

class Abc extends CWebModule
{

    protected $_assetsUrl;

    public function init()
    {
        $path = Yii::app()->module->getAssetsUrl();

        Yii::app()->clientScript->registerCssFile($path.'/css/abc.css', 'all');

       $this->setImport(array(
        'abc.models.*',
        'abc.components.*',
       ));

   }

   public function getAssetsUrl()
    {
        if ($this->_assetsUrl === null)
            $this->_assetsUrl = Yii::app()->getAssetManager()->publish(__DIR__ . '/assets', false, -1, true);
        return $this->_assetsUrl;
    }
}

in the code above i get this error 在上面的代码中,我得到这个错误

Missing argument 1 for CModule::getModule(), called in /Library/WebServer/Documents/dev/common/lib/yii/framework/base/CComponent.php on line 111 and defined

which is this line 这是这条线

$path = Yii::app()->module->getAssetsUrl();

i also tried 我也尝试过

$path = Yii::app()->getModule("Abc")->getAssetsUrl();

but got this error 但是得到这个错误

Fatal error: Call to a member function getAssetsUrl() on a non-object in /Library/WebServer/Documents/dev/frontend/modules/research/AbcModule.php on line 17

in my view i call it like this. 在我看来,我这样称呼它。 and it works perfect 而且效果很好

Yii::app()->clientScript->registerCssFile($this->module->getAssetsUrl().'/css/abc.css', 'all');

any idea what I'm doing wrong? 知道我在做什么错吗?

尝试

$path = $this->getAssetsUrl();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM