我有一个组件datetimepicker
,其资源文件夹js
,css
和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/
文件夹下的所有文件夹和文件都具有写入和读取权限。请帮忙吗?
P.S。我确保Yii::getPathOfAlias('datetimepicker.assets')
返回正确的路径,Yii::app()->assetManager->publish($assetsPath, false, -1, true)
返回合理的字符串 - /assets/d4a0c9d8
。此外,yii
将application/components/datetimepicker/assets/
目录复制到名为application/assets
- d4a0c9d8
的{{1}},但是在html输出中生成了此文件夹中文件的链接文件。
答案 0 :(得分:1)
好的,我误解了资产经理的概念。 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;
}
}