本文整理汇总了PHP中DbHelper::getAuditColumnConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP DbHelper::getAuditColumnConfig方法的具体用法?PHP DbHelper::getAuditColumnConfig怎么用?PHP DbHelper::getAuditColumnConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbHelper
的用法示例。
在下文中一共展示了DbHelper::getAuditColumnConfig方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createTable
/**
* Adds `id`, `dateCreated`, `date_update`, and `uid` columns to $columns, packages up the column definitions into
* strings, and then passes it back to CDbCommand->createTable().
*
* @param string $table
* @param array $columns
* @param null $options
* @param bool $addIdColumn
* @param bool $addAuditColumns
*
* @return int
*/
public function createTable($table, $columns, $options = null, $addIdColumn = true, $addAuditColumns = true)
{
$table = $this->getConnection()->addTablePrefix($table);
$columns = array_merge($addIdColumn ? array('id' => ColumnType::PK) : array(), $columns, $addAuditColumns ? DbHelper::getAuditColumnConfig() : array());
foreach ($columns as $col => $settings) {
$columns[$col] = DbHelper::generateColumnDefinition($settings);
}
// Create the table
return parent::createTable($table, $columns, $options);
}
示例2: _saveContentRow
/**
* Saves a content model to the database.
*
* @param ContentModel $content
*
* @return bool
*/
private function _saveContentRow(ContentModel $content)
{
$values = array('id' => $content->id, 'elementId' => $content->elementId, 'locale' => $content->locale);
$excludeColumns = array_keys($values);
$excludeColumns = array_merge($excludeColumns, array_keys(DbHelper::getAuditColumnConfig()));
$fullContentTableName = craft()->db->addTablePrefix($this->contentTable);
$contentTableSchema = craft()->db->schema->getTable($fullContentTableName);
foreach ($contentTableSchema->columns as $columnSchema) {
if ($columnSchema->allowNull && !in_array($columnSchema->name, $excludeColumns)) {
$values[$columnSchema->name] = null;
}
}
// If the element type has titles, than it's required and will be set. Otherwise, no need to include it (it
// might not even be a real column if this isn't the 'content' table).
if ($content->title) {
$values['title'] = $content->title;
}
foreach (craft()->fields->getFieldsWithContent() as $field) {
$handle = $field->handle;
$value = $content->{$handle};
$values[$this->fieldColumnPrefix . $field->handle] = ModelHelper::packageAttributeValue($value, true);
}
$isNewContent = !$content->id;
if (!$isNewContent) {
$affectedRows = craft()->db->createCommand()->update($this->contentTable, $values, array('id' => $content->id));
} else {
$affectedRows = craft()->db->createCommand()->insert($this->contentTable, $values);
}
if ($affectedRows) {
if ($isNewContent) {
// Set the new ID
$content->id = craft()->db->getLastInsertID();
}
// Fire an 'onSaveContent' event
$this->onSaveContent(new Event($this, array('content' => $content, 'isNewContent' => $isNewContent)));
return true;
} else {
return false;
}
}