本文整理汇总了PHP中yii\db\ActiveRecord::className方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::className方法的具体用法?PHP ActiveRecord::className怎么用?PHP ActiveRecord::className使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::className方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initOptions
/**
* Initializes the widget options.
* This method sets the default values for various options.
*/
protected function initOptions()
{
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
$this->clientOptions = ArrayHelper::merge(['form' => $this->form, 'fieldsUrl' => Url::to(['/eav/backend/attribute/fields']), 'modelClass' => $this->model ? $this->model->className() : ''], $this->clientOptions);
}
示例2: attach
/**
* @inheritdoc
*
* @param ActiveRecord $owner
*
* @throws ErrorException
*/
public function attach($owner)
{
if (!self::$_eventSwitched) {
Event::on($owner->className(), VekActiveRecord::EVENT_TO_SAVE_MULTIPLE, [self::className(), 'logToSaveMultiple']);
Event::on($owner->className(), VekActiveRecord::EVENT_SAVED_MULTIPLE, [self::className(), 'logSavedMultiple']);
}
parent::attach($owner);
}
示例3: run
public function run()
{
$object = app\models\Object::getForClass($this->model->className());
/** @var \app\modules\shop\models\AddonCategory $addonCategories */
$addonCategories = app\components\Helper::getModelMap(AddonCategory::className(), 'id', 'name');
/** @var app\modules\shop\models\Addon $bindedAddons */
$bindedAddons = $this->model->bindedAddons;
$addAddonModel = new AddAddonModel();
return $this->render('addons-widget', ['object' => $object, 'addonCategories' => $addonCategories, 'bindedAddons' => $bindedAddons, 'model' => $this->model, 'form' => $this->form, 'addAddonModel' => $addAddonModel]);
}
示例4: 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;
}
示例5: getQuery
/**
* @return ActiveQuery|ISortableActiveQuery
*/
protected function getQuery()
{
if ($this->query instanceof Closure) {
$query = call_user_func_array($this->query, [$this->owner]);
} else {
if ($this->query instanceof ActiveQuery) {
$query = $this->query;
} else {
/** @var ActiveRecord $className */
$className = $this->owner->className();
$query = $className::find();
}
}
return $query;
}
示例6: init
public function init()
{
$command = null;
if ($this->onInsert) {
Event::on(ActiveRecord::className(), ActiveRecord::EVENT_BEFORE_INSERT, function ($event) {
$db = $event->sender->db;
$values = $event->sender->getDirtyAttributes();
$command = $db->createCommand()->insert($event->sender->tableName(), $values)->rawSql;
});
}
if ($this->onUpdate) {
Event::on(ActiveRecord::className(), ActiveRecord::EVENT_BEFORE_UPDATE, function ($event) {
$db = $event->sender->db;
$values = $event->sender->getDirtyAttributes();
$condition = $event->sender->getOldPrimaryKey(true);
$command = $db->createCommand()->update($event->sender->tableName(), $values, $condition)->rawSql;
});
}
if ($this->onDelete) {
Event::on(ActiveRecord::className(), ActiveRecord::EVENT_BEFORE_DELETE, function ($event) {
$db = $event->sender->db;
$values = $event->sender->getDirtyAttributes();
$condition = $event->sender->getOldPrimaryKey(true);
$command = $db->createCommand()->delete($event->sender->tableName(), $condition)->rawSql;
});
}
Log::save($command);
return parent::init();
}
示例7: attach
/**
* @param \skeeks\cms\base\db\ActiveRecord $owner
* @throws Exception
*/
public function attach($owner)
{
if (!$owner instanceof \yii\db\ActiveRecord) {
throw new Exception(\Yii::t('app', "This behavior is designed only to work with {class}", ['class' => \yii\db\ActiveRecord::className()]));
}
parent::attach($owner);
}
示例8: validate
/**
* @param Component $component
* @return \skeeks\sx\validate\Result
*/
public function validate($component)
{
if (!$component instanceof ActiveRecord) {
return $this->_bad(\Yii::t('app', "Object: {class} must be inherited from: {parent}", ['class' => $component->className(), 'parent' => ActiveRecord::className()]));
}
return !$component->isNewRecord ? $this->_ok() : $this->_bad(\Yii::t('app', "The object must already be saved"));
}
示例9: events
public function events()
{
// 查询事件
// Event::on(
// ActiveRecord::className(),
// ActiveRecord::EVENT_AFTER_FIND, [$this, 'afterFind']
// );
// 写入事件
Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_INSERT, [$this, 'afterInsert']);
// 更新事件
Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_UPDATE, [$this, 'afterUpdate']);
// 删除事件
Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_DELETE, [$this, 'afterDelete']);
// 后台登录事件
Event::on(\service\models\LoginForm::className(), \service\models\LoginForm::EVENT_LOGIN_AFTER, [$this, 'afterBackendLogin']);
// 后台退出事件
Event::on(\service\models\LoginForm::className(), \service\models\LoginForm::EVENT_LOGOUT_BEFORE, [$this, 'beforeBackendLogout']);
return [];
// return [
// ActiveRecord::EVENT_AFTER_FIND => 'afterFind',
// ActiveRecord::EVENT_AFTER_INSERT => 'afterInsert',
// ActiveRecord::EVENT_AFTER_UPDATE => 'afterUpdate',
// ActiveRecord::EVENT_AFTER_DELETE => 'afterDelete',
// \backend\models\LoginForm::EVENT_LOGIN_AFTER => 'afterBackendLogin',
// \backend\models\LoginForm::EVENT_LOGOUT_AFTER => 'afterBackendLogout',
// ];
}
示例10: createEnumeration
public function createEnumeration()
{
$modelClass = $this->enumerationClass;
$enumeration = new $modelClass();
$enumeration->setEntity($this->owner->primaryKey, $this->owner->className());
$enumeration->save();
return $enumeration;
}
示例11: rules
/**
* @inheritdoc
*/
public function rules()
{
return array_merge(parent::rules(), [[['db', 'ns', 'tableName', 'modelClass', 'baseClass', 'queryNs', 'queryClass', 'queryBaseClass'], 'filter', 'filter' => 'trim'], [['ns', 'queryNs'], 'filter', 'filter' => function ($value) {
return trim($value, '\\');
}], [['db', 'ns', 'tableName', 'baseClass', 'queryNs', 'queryBaseClass'], 'required'], [['db', 'modelClass', 'queryClass'], 'match', 'pattern' => '/^\\w+$/', 'message' => 'Only word characters are allowed.'], [['ns', 'baseClass', 'queryNs', 'queryBaseClass'], 'match', 'pattern' => '/^[\\w\\\\]+$/', 'message' => 'Only word characters and backslashes are allowed.'], [['tableName'], 'match', 'pattern' => '/^(\\w+\\.)?([\\w\\*]+)$/', 'message' => 'Only word characters, and optionally an asterisk and/or a dot are allowed.'], [['db'], 'validateDb'], [['ns', 'queryNs'], 'validateNamespace'], [['tableName'], 'validateTableName'], [['modelClass'], 'validateModelClass', 'skipOnEmpty' => false], [['baseClass'], 'validateClass', 'params' => ['extends' => ActiveRecord::className()]], [['queryBaseClass'], 'validateClass', 'params' => ['extends' => ActiveQuery::className()]], [['generateRelations', 'generateLabelsFromComments', 'useTablePrefix', 'useSchemaName', 'generateQuery'], 'boolean'], [['enableI18N'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false], [['imagesDomain', 'imagesPath'], 'filter', 'filter' => 'trim'], [['imagesPath'], 'filter', 'filter' => function ($value) {
return trim($value, '/');
}], [['imagesDomain', 'imagesPath'], 'required'], [['addingI18NStrings'], 'boolean'], [['imagesDomain'], 'match', 'pattern' => '/^(?:[\\w](?:[\\w-]+[\\w])?\\.(?:{\\$domain})|(?:[\\w](?:[0-9\\w\\-\\.]+)?[\\w]\\.[\\w]+))|(?:@[\\w_-]+)$/', 'message' => 'No valid images domain.'], [['messagesPaths'], 'validateMessagesPaths']]);
}
示例12: run
public function run()
{
$cacheKey = static::className() . ':' . implode("_", [$this->model->object->id, $this->model->id, $this->viewFile, $this->limit, $this->offset, $this->thumbnailOnDemand ? '1' : '0', $this->thumbnailWidth, $this->thumbnailHeight, $this->useWatermark]);
$result = Yii::$app->cache->get($cacheKey);
if ($result === false) {
if ($this->offset > 0 || !is_null($this->limit)) {
$images = $this->model->getImages()->limit($this->limit)->offset($this->offset)->all();
} else {
$images = $this->model->images;
}
if ($this->noImageOnEmptyImages === true && count($images) === 0) {
return $this->render('noimage', ['model' => $this->model, 'thumbnailOnDemand' => $this->thumbnailOnDemand, 'thumbnailWidth' => $this->thumbnailWidth, 'thumbnailHeight' => $this->thumbnailHeight, 'useWatermark' => $this->useWatermark, 'additional' => $this->additional]);
}
$result = $this->render($this->viewFile, ['model' => $this->model, 'images' => $images, 'thumbnailOnDemand' => $this->thumbnailOnDemand, 'thumbnailWidth' => $this->thumbnailWidth, 'thumbnailHeight' => $this->thumbnailHeight, 'useWatermark' => $this->useWatermark, 'additional' => $this->additional]);
Yii::$app->cache->set($cacheKey, $result, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Image::className()), ActiveRecordHelper::getCommonTag($this->model->className())]]));
}
return $result;
}
示例13: create
/**
* @param AttributeInfo $rule
* @return AttributeRecord
*/
public function create(AttributeInfo $rule)
{
$class = $rule->attributeRecordClass;
$attributeRecord = new $class();
/** @var AttributeRecord $attributeRecord */
$attributeRecord->setOwner($this->owner->primaryKey, $this->owner->className());
$attributeRecord->setAttributeName($rule->attribute);
return $attributeRecord;
}
示例14: __construct
/**
* Initializes CRUD handler
* @throws \yii\base\ErrorException
*/
public function __construct($model = false)
{
if (!$model) {
$model = $this->modelClass();
}
$this->model = $model;
if (!is_subclass_of($this->model, \yii\db\ActiveRecord::className())) {
throw new \yii\base\ErrorException('Invalid model class. Method "getModelClass" has to retrieve ActiveRecord descendant class.');
}
}
示例15: getLabelColumnName
/**
* Get label column name
* @param ActiveRecord $model
* @return mixed
*/
public static function getLabelColumnName(ActiveRecord $model)
{
$class = $model->className();
if (!isset(self::$label_columns_cache[$class])) {
$schema = $model->getTableSchema();
$available_names = array_intersect(static::$label_column_default, $schema->getColumnNames());
self::$label_columns_cache[$class] = reset($available_names);
}
return self::$label_columns_cache[$class];
}