本文整理汇总了PHP中yii\db\ActiveRecord::tableName方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::tableName方法的具体用法?PHP ActiveRecord::tableName怎么用?PHP ActiveRecord::tableName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::tableName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findOrderNum
/**
* Find and set order numeric
*/
public function findOrderNum()
{
if (!$this->owner->{$this->attribute}) {
$maxOrderNum = (int) (new Query())->select("MAX({$this->attribute})")->from($this->owner->tableName())->scalar();
$this->owner->{$this->attribute} = $maxOrderNum + $this->step;
}
}
示例2: init
public function init()
{
$this->id = $this->model->formName();
$this->action = RequestModule::getPopupUrl(['type' => $this->model->tableName()]);
$this->fieldConfig = ['template' => '<div class="row">{input}{error}</div>', 'errorOptions' => ['class' => 'errorMessage']];
parent::init();
}
示例3: setInsertSort
public function setInsertSort()
{
if (!$this->owner->{$this->attributeName}) {
$query = $this->getQuery();
$query->select(new Expression('MAX(' . $this->attributeName . ')'));
$query->from($this->owner->tableName());
$this->owner->{$this->attributeName} = $query->scalar() + 1;
}
}
示例4: attach
/**
* @inheritdoc
*/
public function attach($owner)
{
parent::attach($owner);
//get config from instance
if ($this->stateConfig === null || $this->stateAttribute === null) {
$this->modelInstance = new $this->owner->modelClass();
$this->stateAttribute = $this->modelInstance->tableName() . '.' . $this->modelInstance->stateAttribute;
$this->stateConfig = $this->modelInstance->stateConfig;
}
}
示例5: search
public function search($params)
{
/* @var $query \yii\db\ActiveQuery */
$query = $this->baseModel->find();
$table_inheritance_joined = false;
$dataProvider = new ActiveDataProvider(['query' => &$query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
if (!$this->load($params)) {
return $dataProvider;
}
$object = Object::getForClass($this->baseModel->className());
$baseModelTableName = $this->baseModel->tableName();
$eavJoinsCount = 0;
$osvJoinsCount = 0;
foreach ($this->propertyGroups as $groupId => $properties) {
foreach ($properties as $key => $propertyValue) {
/** @var \app\properties\PropertyValue $propertyValue */
$prop = Property::findById($propertyValue->property_id);
if (empty($this->{$prop->key}) === true && $this->{$prop->key} !== '0') {
continue;
}
// determine property storage type and join needed table if needed
if ($prop->is_column_type_stored) {
if ($table_inheritance_joined === false) {
$table_inheritance_joined = true;
$query->join('INNER JOIN', $object->column_properties_table_name . ' ti', 'ti.object_model_id = ' . $baseModelTableName . '.id');
}
if ($prop->value_type === 'STRING' && $prop->property_handler_id !== 3) {
$query->andFilterWhere(['like', 'ti.' . $prop->key, $this->{$prop->key}]);
} else {
$query->andFilterWhere(['ti.' . $prop->key => $this->{$prop->key}]);
}
} elseif ($prop->is_eav) {
$eavJoinsCount++;
$eavTableName = 'eav' . $eavJoinsCount;
$key = 'key' . $eavJoinsCount;
$query->join('INNER JOIN', "{$object->eav_table_name} {$eavTableName}", $eavTableName . '.object_model_id = ' . $baseModelTableName . ".id AND {$eavTableName}.key=:{$key}", [$key => $prop->key]);
if ($prop->value_type === 'STRING' && $prop->property_handler_id !== 3) {
$query->andFilterWhere(['like', $eavTableName . '.value', $this->{$prop->key}]);
} else {
// numeric - direct match
$query->andFilterWhere([$eavTableName . '.value' => $this->{$prop->key}]);
}
} elseif ($prop->has_static_values) {
$osvJoinsCount++;
$osvTableName = 'osv' . $osvJoinsCount;
$query->join('INNER JOIN', "object_static_values {$osvTableName}", "{$osvTableName}.object_id={$object->id} AND {$osvTableName}.object_model_id={$baseModelTableName}.id");
// numeric - direct match
$query->andFilterWhere(["{$osvTableName}.property_static_value_id", $this->{$prop->key}]);
}
}
}
return $dataProvider;
}
示例6: tableName
public static function tableName()
{
if (self::$_table) {
return \Yii::$app->getDb()->tablePrefix . self::$_table;
}
return parent::tableName();
}
示例7: run
/**
* @param integer $type
* @param \yii\db\ActiveRecord $object
*/
public function run($type, $object)
{
$pkey = $object->primaryKey();
$pkey = $pkey[0];
$data = ['table' => $object->tableName(true), 'model_id' => $object->getPrimaryKey(), 'type' => $type, 'date' => date('Y-m-d H:i:s', time())];
switch ($type) {
case self::EVT_INSERT:
$data['field_name'] = $pkey;
$this->saveField($data);
break;
case self::EVT_UPDATE:
foreach ($this->updatedFields as $updatedFieldKey => $updatedFieldValue) {
$data['field_name'] = $updatedFieldKey;
$data['old_value'] = $updatedFieldValue;
$data['new_value'] = $object->{$updatedFieldKey};
$this->saveField($data);
}
break;
case self::EVT_DELETE:
$data['field_name'] = $pkey;
$this->saveField($data);
break;
case self::EVT_UPDATE_PK:
$data['field_name'] = $pkey;
$data['old_value'] = $object->getOldPrimaryKey();
$data['new_value'] = $object->{$pkey};
$this->saveField($data);
break;
}
}
示例8: tableName
/**
* Get table name of SEO data table for ActiveRecord
* @param ActiveRecord $activeRecord
* @return string
*/
public static function tableName(ActiveRecord $activeRecord)
{
$tableName = $activeRecord->tableName();
if (substr($tableName, -2) == '}}') {
return preg_replace('/{{(.+)}}/', '{{$1_' . self::$tableSuffix . '}}', $tableName);
} else {
return $tableName . '_' . self::$tableSuffix;
}
}
示例9: attach
/**
* @inheritdoc
* @param \yii\db\ActiveRecord $owner
*/
public function attach($owner)
{
//assert owner extends class ActiveRecord
if (!$owner instanceof ActiveRecord) {
throw new InvalidConfigException('ArchiveBehavior can only be applied to classes extending \\yii\\db\\ActiveRecord');
}
if ($owner->tableSchema->getColumn($this->archiveAttribute) === null) {
throw new InvalidConfigException(sprintf('The table %s does not contain a column named %s', $owner->tableName(), $this->archiveAttribute));
}
parent::attach($owner);
}
示例10: attributeValue
public function attributeValue(ActiveRecord $model, $fieldName)
{
$complexName = $model->tableName() . '.' . $fieldName;
$decode = \Yii::$app->params['decode'];
$key = $model->{$fieldName};
if ($key !== null && isset($decode[$complexName])) {
return $decode[$complexName][$key];
} else {
return $key;
}
}
示例11: storeDataRecord
/**
* Store data record and track change statistics
*
* @param ActiveRecord $ActiveRecord
*
* @return bool false if not saved
*/
protected function storeDataRecord(ActiveRecord $ActiveRecord)
{
if ($ActiveRecord->getDirtyAttributes()) {
$unsaved_record = clone $ActiveRecord;
// Save record
if (!$ActiveRecord->save()) {
// Create error message
$message = "Save error: " . json_encode($ActiveRecord->errors) . "\n";
$message .= "Record data: " . json_encode($ActiveRecord->getAttributes()) . "\n";
trigger_error($message, E_USER_WARNING);
$this->incStat('error_' . $ActiveRecord->tableName());
return false;
}
// Store statistics
if ($unsaved_record->isNewRecord) {
$this->incStat('new_' . $ActiveRecord->tableName());
} else {
$this->incStat('update_' . $ActiveRecord->tableName());
}
}
return true;
}
示例12: find
public static function find()
{
$tenantTableName = '{{%tenant}}';
$field = '';
$model = parent::find();
if (parent::tableName() == $tenantTableName) {
$field = '.id';
} else {
$field = '.tenant_id';
}
$model->where([parent::tableName() . $field => Yii::$app->session['tenant']]);
return $model;
}
示例13: asJson
/**
* Returns a models primary-key in json format. This works also with
* composite primary-keys
*
* @param \yii\db\ActiveRecord $model the model instance
* @return string the models pk in json-format
* @throws \yii\base\InvalidParamException if the model is not of type ActiveRecord
* @throws \yii\base\InvalidConfigException if the models pk is empty or invalid
*/
public static function asJson($model)
{
//check if the model is valid
if (!$model instanceof \yii\db\ActiveRecord) {
throw new InvalidParamException(Yii::t('app', 'The model must be of type ActiveRecord'));
}
//fetch the models pk
$pk = $model->primaryKey();
//assert that a valid pk was received
if ($pk === null || !is_array($pk) || count($pk) == 0) {
$msg = Yii::t('app', 'Invalid primary key definition: please provide a pk-definition for table {table}', ['table' => $model->tableName()]);
throw new InvalidConfigException($msg);
}
//create final array and return it
$arrPk = [];
foreach ($pk as $pkCol) {
$arrPk[$pkCol] = $model->{$pkCol};
}
return Json::encode($arrPk);
}
示例14: dropCaches
/**
* @param ActiveRecord $model
* @param array $changedAttributes
*/
public static function dropCaches($model, array $changedAttributes = [])
{
self::initialize();
$attrs = $model->getAttributes();
$changed = [];
if ($changedAttributes) {
$attrNames = array_keys($changedAttributes);
foreach ($attrNames as $attrName) {
if (array_key_exists($attrName, $attrs)) {
$changed[$attrName] = $attrs[$attrName];
}
}
}
$args = [$model->tableName(), json_encode($attrs, self::$jsonOptions), json_encode($changed, self::$jsonOptions)];
CacheHelper::evalSHA(self::$shaInvalidate, $args, 0);
}
示例15: updateOwner
/**
* @param integer $fileId
* @return int
* @throws Exception
*/
protected function updateOwner($fileId)
{
$this->owner->updateAttributes([$this->attribute => $fileId]);
$sql = "\n UPDATE " . $this->owner->tableName() . "\n SET " . $this->attribute . " = :file\n WHERE id = :id\n ";
return Yii::$app->db->createCommand($sql)->bindValue(':file', $fileId)->bindValue(':id', $this->owner->primaryKey)->execute();
}