本文整理汇总了PHP中CategoryModel::getUrlFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::getUrlFormat方法的具体用法?PHP CategoryModel::getUrlFormat怎么用?PHP CategoryModel::getUrlFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CategoryModel
的用法示例。
在下文中一共展示了CategoryModel::getUrlFormat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepForFieldType
/**
* Prepare fields for fieldtypes.
*
* @param string &$data
* @param string $handle
*
* @return mixed
*/
public function prepForFieldType(&$data, $handle)
{
// Fresh up $data
$data = StringHelper::convertToUTF8($data);
$data = trim($data);
// Get field info
$field = craft()->fields->getFieldByHandle($handle);
// If it's a field ofcourse
if (!is_null($field)) {
// For some fieldtypes the're special rules
switch ($field->type) {
case ImportModel::FieldTypeEntries:
// No newlines allowed
$data = str_replace("\n", '', $data);
$data = str_replace("\r", '', $data);
// Don't connect empty fields
if (!empty($data)) {
// Get field settings
$settings = $field->getFieldType()->getSettings();
// Get source id's for connecting
$sectionIds = array();
$sources = $settings->sources;
if (is_array($sources)) {
foreach ($sources as $source) {
list($type, $id) = explode(':', $source);
$sectionIds[] = $id;
}
}
// Find matching element in sections
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->sectionId = $sectionIds;
$criteria->limit = $settings->limit;
// Get search strings
$search = ArrayHelper::stringToArray($data);
// Ability to import multiple Assets at once
$data = array();
// Loop through keywords
foreach ($search as $query) {
// Search
$criteria->search = $query;
// Add to data
$data = array_merge($data, $criteria->ids());
}
} else {
// Return empty array
$data = array();
}
break;
case ImportModel::FieldTypeCategories:
// Don't connect empty fields
if (!empty($data)) {
// Get field settings
$settings = $field->getFieldType()->getSettings();
// Get source id
$source = $settings->source;
list($type, $id) = explode(':', $source);
// Get category data
$category = new CategoryModel();
$category->groupId = $id;
// This we append before the slugified path
$categoryUrl = str_replace('{slug}', '', $category->getUrlFormat());
// Find matching elements in categories
$criteria = craft()->elements->getCriteria(ElementType::Category);
$criteria->groupId = $id;
$criteria->limit = $settings->limit;
// Get search strings
$search = ArrayHelper::stringToArray($data);
// Ability to import multiple Categories at once
$data = array();
// Loop through keywords
foreach ($search as $query) {
// Find matching element by URI (dirty, not all categories have URI's)
$criteria->uri = $categoryUrl . $this->slugify($query);
// Add to data
$data = array_merge($data, $criteria->ids());
}
} else {
// Return empty array
$data = array();
}
break;
case ImportModel::FieldTypeAssets:
// Don't connect empty fields
if (!empty($data)) {
// Get field settings
$settings = $field->getFieldType()->getSettings();
// Get folder id's for connecting
$folderIds = array();
$folders = $settings->sources;
if (is_array($folders)) {
foreach ($folders as $folder) {
list($type, $id) = explode(':', $folder);
//.........这里部分代码省略.........
示例2: prepCategoriesFieldType
/**
* @param string $data
* @param FieldModel $field
*
* @return array
*/
private function prepCategoriesFieldType($data, FieldModel $field)
{
// Get field settings
$settings = $field->getFieldType()->getSettings();
// Get source id
$source = $settings->getAttribute('source');
list(, $id) = explode(':', $source);
// Get category data
$category = new CategoryModel();
$category->groupId = $id;
// This we append before the slugified path
$categoryUrl = str_replace('{slug}', '', $category->getUrlFormat());
// Find matching elements in categories
$criteria = craft()->elements->getCriteria(ElementType::Category);
$criteria->groupId = $id;
$criteria->limit = $settings->limit;
// Get search strings
$search = ArrayHelper::stringToArray($data);
// Ability to import multiple Categories at once
$data = array();
// Loop through keywords
foreach ($search as $query) {
// Find matching element by URI (dirty, not all categories have URI's)
$criteria->uri = $categoryUrl . $this->slugify($query);
// Add to data
$data = array_merge($data, $criteria->ids());
}
return $data;
}