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


PHP CategoryModel::getContent方法代码示例

本文整理汇总了PHP中CategoryModel::getContent方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::getContent方法的具体用法?PHP CategoryModel::getContent怎么用?PHP CategoryModel::getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CategoryModel的用法示例。


在下文中一共展示了CategoryModel::getContent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _populateCategoryModel

 /**
  * Populates an CategoryModel with post data.
  *
  * @param CategoryModel $category
  *
  * @return null
  */
 private function _populateCategoryModel(CategoryModel $category)
 {
     // Set the category attributes, defaulting to the existing values for whatever is missing from the post data
     $category->slug = craft()->request->getPost('slug', $category->slug);
     $category->enabled = (bool) craft()->request->getPost('enabled', $category->enabled);
     $category->getContent()->title = craft()->request->getPost('title', $category->title);
     $fieldsLocation = craft()->request->getParam('fieldsLocation', 'fields');
     $category->setContentFromPost($fieldsLocation);
     // Parent
     $parentId = craft()->request->getPost('parentId');
     if (is_array($parentId)) {
         $parentId = isset($parentId[0]) ? $parentId[0] : null;
     }
     $category->newParentId = $parentId;
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:22,代码来源:CategoriesController.php

示例2: actionCreateCategory

 /**
  * Saves a category.
  *
  * @return null
  */
 public function actionCreateCategory()
 {
     $this->requireLogin();
     $this->requireAjaxRequest();
     $groupId = craft()->request->getRequiredPost('groupId');
     craft()->userSession->requirePermission('editCategories:' . $groupId);
     $category = new CategoryModel();
     $category->groupId = $groupId;
     $category->getContent()->title = craft()->request->getPost('title');
     if (craft()->categories->saveCategory($category)) {
         $this->returnJson(array('success' => true, 'id' => $category->id, 'title' => $category->title, 'status' => $category->getStatus(), 'url' => $category->getUrl()));
     } else {
         $this->returnJson(array('success' => false));
     }
 }
开发者ID:kant312,项目名称:sop,代码行数:20,代码来源:CategoriesController.php

示例3: prepCategories

 public function prepCategories($data, $field)
 {
     $fieldData = array();
     if (!empty($data)) {
         $settings = $field->getFieldType()->getSettings();
         // Get category group id
         $source = $settings->getAttribute('source');
         list($type, $groupId) = explode(':', $source);
         $categories = ArrayHelper::stringToArray($data);
         foreach ($categories as $category) {
             // Skip empty
             if (empty($category)) {
                 continue;
             }
             $categoryArray = array();
             $category = DbHelper::escapeParam($category);
             // Find existing category by title or slug
             $criteria = craft()->elements->getCriteria(ElementType::Category);
             $criteria->groupId = $groupId;
             $criteria->limit = 1;
             $query = craft()->elements->buildElementsQuery($criteria);
             $query->select('elements.id');
             $conditions = array('or', array('in', 'title', $category), array('in', 'slug', $category));
             $query->andWhere($conditions);
             $results = $query->queryAll();
             if (!empty($results)) {
                 foreach ($results as $result) {
                     $categoryArray = [$result['id']];
                 }
             } else {
                 // Create category if one doesn't already exist
                 $newCategory = new CategoryModel();
                 $newCategory->getContent()->title = $category;
                 $newCategory->groupId = $groupId;
                 // Save category
                 if (craft()->categories->saveCategory($newCategory)) {
                     $categoryArray = [$newCategory->id];
                 }
             }
             // Add categories to data array
             $fieldData = array_merge($fieldData, $categoryArray);
         }
     }
     // Check for field limit - only return the specified amount
     if ($fieldData) {
         if ($field->settings['limit']) {
             $fieldData = array_chunk($fieldData, $field->settings['limit']);
             $fieldData = $fieldData[0];
         }
     }
     return $fieldData;
 }
开发者ID:Tcheu,项目名称:FeedMe,代码行数:52,代码来源:FeedMe_FieldsService.php

示例4: _importCategory

 /**
  * Saves category from wordpress
  *
  * @param string $title Title for new/existing category
  * @param number $categoryGroupId Category group id for saving category
  *
  * @return integer Id for category.
  */
 protected function _importCategory($title, $categoryGroupId)
 {
     // Check to see if category exists
     $criteria = craft()->elements->getCriteria(ElementType::Category);
     $criteria->groupId = $categoryGroupId;
     $criteria->status = null;
     $criteria->limit = null;
     $findCategories = $criteria->find();
     $match = false;
     foreach ($findCategories as $findCategory) {
         if ($findCategory->title == $title) {
             return $findCategory->id;
         }
     }
     // Save the category
     $category = new CategoryModel();
     $category->groupId = $categoryGroupId;
     $category->getContent()->title = $title;
     if (!craft()->categories->saveCategory($category)) {
         Craft::log('Couldn’t save the category "' . $title . '"', LogLevel::Warning, true, '_importCategory', 'InstaBlog');
         return false;
     } else {
         return $category->id;
     }
 }
开发者ID:lukeholder,项目名称:craft-instablog,代码行数:33,代码来源:InstaBlog_ImportService.php

示例5: prepCategories

 public function prepCategories($data, $field)
 {
     $fieldData = array();
     if (!empty($data)) {
         $settings = $field->getFieldType()->getSettings();
         // Get category group id
         $source = $settings->getAttribute('source');
         list($type, $groupId) = explode(':', $source);
         $categories = ArrayHelper::stringToArray($data);
         foreach ($categories as $category) {
             $categoryArray = array();
             if (!empty($category)) {
                 // Find existing category
                 $criteria = craft()->elements->getCriteria(ElementType::Category);
                 $criteria->title = DbHelper::escapeParam($category);
                 $criteria->groupId = $groupId;
                 $criteria->limit = 1;
                 if (!$criteria->total()) {
                     // Create category if one doesn't already exist
                     $newCategory = new CategoryModel();
                     $newCategory->getContent()->title = $category;
                     $newCategory->groupId = $groupId;
                     // Save category
                     if (craft()->categories->saveCategory($newCategory)) {
                         $categoryArray = array($newCategory->id);
                     }
                 } else {
                     $categoryArray = $criteria->ids();
                 }
             }
             // Add categories to data array
             $fieldData = array_merge($fieldData, $categoryArray);
         }
     }
     // Check for field limit - only return the specified amount
     if ($fieldData) {
         if ($field->settings['limit']) {
             $fieldData = array_chunk($fieldData, $field->settings['limit']);
             $fieldData = $fieldData[0];
         }
     }
     return $fieldData;
 }
开发者ID:am-impact,项目名称:FeedMe,代码行数:43,代码来源:FeedMe_FieldsService.php


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