本文整理汇总了PHP中CategoryModel::getGroup方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::getGroup方法的具体用法?PHP CategoryModel::getGroup怎么用?PHP CategoryModel::getGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CategoryModel
的用法示例。
在下文中一共展示了CategoryModel::getGroup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _showCategory
/**
* Displays a category.
*
* @param CategoryModel $category
*
* @throws HttpException
* @return null
*/
private function _showCategory(CategoryModel $category)
{
$group = $category->getGroup();
if (!$group) {
Craft::log('Attempting to preview a category that doesn’t have a group', LogLevel::Error);
throw new HttpException(404);
}
craft()->setLanguage($category->locale);
// Have this category override any freshly queried categories with the same ID/locale
craft()->elements->setPlaceholderElement($category);
craft()->templates->getTwig()->disableStrictVariables();
$this->renderTemplate($group->template, array('category' => $category));
}
示例2: fields
/**
* Parse category fields.
*
* @param CategoryModel $category
* @param bool $empty
*
* @return array
*/
public function fields(CategoryModel $category, $empty = false)
{
// Always save id
$fields = array('id' => array('label' => Craft::t('ID'), 'value' => $category->id), 'title' => array('label' => Craft::t('Title'), 'value' => (string) $category->getTitle()), 'group' => array('label' => Craft::t('Group'), 'value' => (string) $category->getGroup()));
// Get element type
$elementType = craft()->elements->getElementType(ElementType::Category);
// Get nice attributes
$availableAttributes = $elementType->defineAvailableTableAttributes();
// Make 'em fit
$attributes = array();
foreach ($availableAttributes as $key => $result) {
$attributes[$key] = $result['label'];
}
// Get static "fields"
foreach ($category->getAttributes() as $handle => $value) {
// Only show nice attributes
if (array_key_exists($handle, $attributes)) {
$fields[$handle] = array('label' => $attributes[$handle], 'value' => StringHelper::arrayToString(is_array($value) ? array_filter(ArrayHelper::flattenArray($value), 'strlen') : $value, ', '));
}
}
// Get fieldlayout
foreach (craft()->fields->getLayoutByType(ElementType::Category)->getFields() as $field) {
// Get field values
$field = $field->getField();
$handle = $field->handle;
$label = $field->name;
$value = $empty ? '' : craft()->auditLog->parseFieldData($handle, $category->{$handle});
// Set on fields
$fields[$handle] = array('label' => $label, 'value' => $value);
}
// Return
return $fields;
}