当前位置: 首页>>代码示例>>PHP>>正文


PHP CategoryModel::getUrlFormat方法代码示例

本文整理汇总了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);
//.........这里部分代码省略.........
开发者ID:ianshea,项目名称:import,代码行数:101,代码来源:ImportService.php

示例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;
 }
开发者ID:transomdesign,项目名称:transom-craft-starter,代码行数:35,代码来源:ImportService.php


注:本文中的CategoryModel::getUrlFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。