本文整理匯總了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);
}
}
}