本文整理汇总了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;
}
示例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));
}
}
示例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;
}
示例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;
}
}
示例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;
}