1

我有一个datetimepicker带有 assets 文件夹的组件jscss并且img不为空:

application/components
application/components/datetimepicker/assets
application/components/datetimepicker/assets/js
application/components/datetimepicker/assets/css
application/components/datetimepicker/assets/img

我尝试assets通过一次调用publish方法来发布整个文件夹yii Asset Manager

$assetsPath = Yii::getPathOfAlias('datetimepicker.assets');
$assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1, true);

但它不发布任何东西。文件夹下的所有文件夹和文件application/都有读写权限。有人可以帮忙吗?

PS我确保Yii::getPathOfAlias('datetimepicker.assets')返回正确的路径并Yii::app()->assetManager->publish($assetsPath, false, -1, true)返回合理的字符串 - /assets/d4a0c9d8。还将yii整个application/components/datetimepicker/assets/目录复制到application/assets名称d4a0c9d8-下application/assets/d4a0c9d8,但在 html 输出文件中生成指向此文件夹中文件的链接。

4

1 回答 1

1

好的,我误解了 Assets Manager 的概念。该publish方法仅将文件从自定义小部件的目录复制到主assests目录。(即to publish== to copy)并且您仍然需要注册脚本和 css 文件以指出它们的顺序。正确的?

例子

public function registerAssetJs($jsFile, $position = NULL)
{
    Yii::app()->getClientScript()->registerScriptFile($this->getAssetsUrl() . "/js/{$jsFile}", $position);
}

public function registerAssetCss($cssFile, $media = '')
{
    Yii::app()->getClientScript()->registerCssFile($this->getAssetsUrl() . "/css/{$cssFile}", $media);
}   

public function getAssetsUrl()
{
    if (isset($this->_assetsUrl))
        return $this->_assetsUrl;
    else
    {
        $assetsPath = Yii::getPathOfAlias('datetimepicker.assets');
        $assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1, YII_DEBUG);
        return $this->_assetsUrl = $assetsUrl;
    }
}
于 2013-07-09T12:18:19.723 回答