本文整理汇总了PHP中CategoryModel::populateModel方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::populateModel方法的具体用法?PHP CategoryModel::populateModel怎么用?PHP CategoryModel::populateModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CategoryModel
的用法示例。
在下文中一共展示了CategoryModel::populateModel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onBeforeSaveCategory
/**
* Handle the onBeforeSaveCategory event.
*
* @param Event $event
*/
public function onBeforeSaveCategory(Event $event)
{
// Get category id to save
$id = $event->params['category']->id;
if (!$event->params['isNewCategory']) {
// Get old category from db
$category = CategoryModel::populateModel(CategoryRecord::model()->findById($id));
// Get fields
$this->before = $this->fields($category);
} else {
// Get fields
$this->before = $this->fields($event->params['category'], true);
}
}
示例2: populateElementModel
/**
* @inheritDoc IElementType::populateElementModel()
*
* @param array $row
*
* @return array
*/
public function populateElementModel($row)
{
return CategoryModel::populateModel($row);
}
示例3: log
/**
* Initialize the category saving/deleting events.
*/
public function log()
{
// Get values before saving
craft()->on('categories.onBeforeSaveCategory', function (Event $event) {
// Get category id to save
$id = $event->params['category']->id;
if (!$event->params['isNewCategory']) {
// Get old category from db
$category = CategoryModel::populateModel(CategoryRecord::model()->findById($id));
// Get fields
craft()->auditLog_category->before = craft()->auditLog_category->fields($category);
} else {
// Get fields
craft()->auditLog_category->before = craft()->auditLog_category->fields($event->params['category'], true);
}
});
// Get values after saving
craft()->on('categories.onSaveCategory', function (Event $event) {
// Get saved category
$category = $event->params['category'];
// Get fields
craft()->auditLog_category->after = craft()->auditLog_category->fields($category);
// New row
$log = new AuditLogRecord();
// Get user
$user = craft()->userSession->getUser();
// Set user id
$log->userId = $user ? $user->id : null;
// Set element type
$log->type = ElementType::Category;
// Set origin
$log->origin = craft()->request->isCpRequest() ? craft()->config->get('cpTrigger') . '/' . craft()->request->path : craft()->request->path;
// Set before
$log->before = craft()->auditLog_category->before;
// Set after
$log->after = craft()->auditLog_category->after;
// Set status
$log->status = $event->params['isNewCategory'] ? AuditLogModel::CREATED : AuditLogModel::MODIFIED;
// Save row
$log->save(false);
// Callback
craft()->auditLog->elementHasChanged(ElementType::Category, $category->id, craft()->auditLog_category->before, craft()->auditLog_category->after);
});
// Get values before deleting
craft()->on('categories.onBeforeDeleteCategory', function (Event $event) {
// Get deleted category
$category = $event->params['category'];
// Get fields
craft()->auditLog_category->before = craft()->auditLog_category->fields($category);
craft()->auditLog_category->after = craft()->auditLog_category->fields($category, true);
// New row
$log = new AuditLogRecord();
// Set user id
$log->userId = craft()->userSession->getUser()->id;
// Set element type
$log->type = ElementType::Category;
// Set origin
$log->origin = craft()->request->isCpRequest() ? craft()->config->get('cpTrigger') . '/' . craft()->request->path : craft()->request->path;
// Set before
$log->before = craft()->auditLog_category->before;
// Set after
$log->after = craft()->auditLog_category->after;
// Set status
$log->status = AuditLogModel::DELETED;
// Save row
$log->save(false);
// Callback
craft()->auditLog->elementHasChanged(ElementType::Category, $category->id, craft()->auditLog_category->before, craft()->auditLog_category->after);
});
}