本文整理汇总了PHP中AssetsHelper::generateUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetsHelper::generateUrl方法的具体用法?PHP AssetsHelper::generateUrl怎么用?PHP AssetsHelper::generateUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssetsHelper
的用法示例。
在下文中一共展示了AssetsHelper::generateUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUrlForFile
/**
* Get URL for a file.
*
* @param AssetFileModel $file
* @param string $transform
*
* @return string
*/
public function getUrlForFile(AssetFileModel $file, $transform = null)
{
if (!$transform || !ImageHelper::isImageManipulatable(IOHelper::getExtension($file->filename))) {
$sourceType = craft()->assetSources->getSourceTypeById($file->sourceId);
return AssetsHelper::generateUrl($sourceType, $file);
}
// Get the transform index model
$index = craft()->assetTransforms->getTransformIndex($file, $transform);
// Does the file actually exist?
if ($index->fileExists) {
return craft()->assetTransforms->getUrlForTransformByTransformIndex($index);
} else {
if (craft()->config->get('generateTransformsBeforePageLoad')) {
// Mark the transform as in progress
$index->inProgress = true;
craft()->assetTransforms->storeTransformIndexData($index);
// Generate the transform
craft()->assetTransforms->generateTransform($index);
// Update the index
$index->fileExists = true;
craft()->assetTransforms->storeTransformIndexData($index);
// Return the transform URL
return craft()->assetTransforms->getUrlForTransformByTransformIndex($index);
} else {
// Queue up a new Generate Pending Transforms task, if there isn't one already
if (!craft()->tasks->areTasksPending('GeneratePendingTransforms')) {
craft()->tasks->createTask('GeneratePendingTransforms');
}
// Return the temporary transform URL
return UrlHelper::getResourceUrl('transforms/' . $index->id);
}
}
}