本文整理汇总了PHP中yii\db\ActiveRecord::hasAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::hasAttribute方法的具体用法?PHP ActiveRecord::hasAttribute怎么用?PHP ActiveRecord::hasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::hasAttribute方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hasAttribute
public function hasAttribute($name)
{
if (!empty($this->{$name})) {
return true;
}
return parent::hasAttribute($name);
}
示例2: afterFind
/**
* Handle 'afterFind' event of the owner.
*/
public function afterFind()
{
if ($this->owner->isRelationPopulated('translations') && ($related = $this->owner->getRelatedRecords()['translations'])) {
$translations = $this->indexByLanguage($related);
foreach ($this->availableLanguages as $lang) {
foreach ($this->attributes as $attribute) {
foreach ($translations as $translation) {
if ($translation->{$this->languageField} == $lang) {
$this->setTranslateAttribute($attribute . '_' . $lang, $translation->{$attribute});
if ($lang == Yii::$app->language) {
$this->setTranslateAttribute($attribute, $translation->{$attribute});
}
}
}
}
}
} else {
if (!$this->owner->isRelationPopulated('translation')) {
$this->owner->translation;
}
$translation = $this->owner->getRelatedRecords()['translation'];
if ($translation) {
foreach ($this->attributes as $attribute) {
$this->owner->setTranslateAttribute($attribute, $translation->{$attribute});
}
}
}
foreach ($this->attributes as $attribute) {
if ($this->owner->hasAttribute($attribute) && $this->getTranslateAttribute($attribute)) {
$this->owner->setAttribute($attribute, $this->getTranslateAttribute($attribute));
}
}
}
示例3: hasAttribute
public function hasAttribute($name)
{
$class = get_class($this);
if (!isset(self::$hasAttributeCache[$class][$name])) {
self::$hasAttributeCache[$class][$name] = parent::hasAttribute($name);
}
return self::$hasAttributeCache[$class][$name];
}
示例4: validateInputParams
/**
* Проверка входящих параметров
*
* @throws \yii\base\Exception
*/
private function validateInputParams()
{
if (is_null($this->model)) {
throw new Exception('Параметр model не задан');
}
if (!$this->model instanceof ActiveRecord) {
throw new Exception('Параметр model должен быть объектом класса ActiveRecord');
}
if (!is_null($this->author)) {
if (!$this->author instanceof ActiveRecord) {
throw new Exception('Параметр author должен быть объектом класса ActiveRecord');
}
if (!is_null($this->authorNameAttribute) && !$this->author->hasAttribute($this->authorNameAttribute)) {
throw new Exception('Параметр author не содержит свойство ' . $this->authorNameAttribute);
}
if (!is_null($this->authorAvatarAttribute) && !$this->author->hasAttribute($this->authorAvatarAttribute)) {
throw new Exception('Параметр author не содержит свойство ' . $this->authorAvatarAttribute);
}
}
}
示例5: saveTempFiles
/**
* @inheritdoc
* @return array
* @throws InvalidConfigException
*/
public function saveTempFiles()
{
if ($this->key === null) {
throw new InvalidConfigException('You must specify key');
}
if ($this->saveDirectoryName === null) {
throw new InvalidConfigException('You must specify saveDirectoryName');
}
if ($this->saveFileModel === null) {
throw new InvalidConfigException('You must specify save model');
}
if (!$this->saveFileModel instanceof ActiveRecord) {
throw new InvalidConfigException('Save model must be instance of ActiveRecord');
}
if ($this->saveFileAttribute === null) {
throw new InvalidConfigException('You must specify save attribute');
}
if ($this->saveFileRelatedAttribute === null) {
throw new InvalidConfigException('You must specify related attribute');
}
if (!$this->saveFileModel->hasAttribute($this->saveFileAttribute)) {
throw new InvalidConfigException("{$this->saveFileModel->className()} has no attribute name {$this->saveFileAttribute}");
}
$files = Yii::$app->session->get($this->key, []);
foreach ($files as $file) {
$oldPath = $file['path'];
$newPath = Yii::$app->params['uploadsPath'] . "/{$this->saveDirectoryName}/" . ($newPath = "{$file['name']}");
if (file_exists($oldPath)) {
if (copy($oldPath, $newPath)) {
$fileModel = new $this->saveFileModel([$this->saveFileAttribute => $file['name'], $this->saveFileRelatedAttribute => $this->messageModel->id]);
$fileModel->save();
}
}
}
$this->clearTempFolder();
}
示例6: appendToObjectModel
/**
* @param ActiveRecord|HasProperties $model
* @param string $idAttribute
* @return bool
*/
public function appendToObjectModel(ActiveRecord $model, $idAttribute = 'id')
{
$object = Object::getForClass($model::className());
if (null === $object || !$model->hasAttribute($idAttribute)) {
return false;
}
$link = new ObjectPropertyGroup();
$link->object_id = $object->id;
$link->object_model_id = $model->{$idAttribute};
$link->property_group_id = $this->id;
$result = $link->save();
$model->updatePropertyGroupsInformation();
return $result;
}
示例7: processEmailStatus
/**
* Determine status of one email AR. Be called after every email sent.
* Result statuc can be "succeed", "failed" or "retry".
* @param CActiveRecord $ar
* @param bool $isSent
*/
protected function processEmailStatus(\yii\db\ActiveRecord &$mail, $isSent)
{
if (!($mail->hasAttribute($this->retryAttr) && $this->retryTimes > 0)) {
$mail->{$this->statusAttr} = $isSent ? self::ST_SUCCEED : self::ST_FAILED;
return;
}
if ($isSent) {
if ($mail->{$this->statusAttr} == self::ST_RETRY) {
// Current is a retry sending.
$mail->{$this->retryAttr}++;
}
$mail->{$this->statusAttr} = self::ST_SUCCEED;
} else {
if ($mail->{$this->statusAttr} == self::ST_NEVER) {
// First sending and retryable
$mail->{$this->retryAttr} = 0;
$mail->{$this->statusAttr} = self::ST_RETRY;
} elseif (++$mail->{$this->retryAttr} < $this->retryTimes && $mail->{$this->statusAttr} == self::ST_RETRY) {
// Retry sending and still retryable for next time
} else {
// Final failed.
$mail->{$this->statusAttr} = self::ST_FAILED;
}
}
}
示例8: hasAttribute
/**
* Returns a value indicating whether the model has an attribute with the specified name.
* @param string $name the name of the attribute
* @return boolean whether the model has an attribute with the specified name.
*/
public function hasAttribute($name)
{
$result = parent::hasAttribute($name);
if (!$this->applyDefaults || $this->defaultsApplied) {
return $result;
}
if ($this->getIsNewRecord() && $result) {
$this->applyDefaults(false);
}
return $result;
}
示例9: updateAddr
/**
* 根据$addr以及跟新数据更新收货地址
*
* $addr = self::find()->where($condition)->one();
*
* @param \yii\db\ActiveRecord|\yii\db\ActiveRecord[] $addr 收货地址model对象
* @param array $data 更新数据
* ~
* [
* 'id' => '主键ID', 'addressee' => '', 'mobile' => '',
* 'county' => '', 'address' => '', 'post_code' => '',
* ]
* ~
*
* @return bool
*/
public function updateAddr($addr, $data)
{
foreach ($data as $field => $val) {
if ($addr->hasAttribute($field)) {
$addr->{$field} = $val;
}
}
$addr->update_time = time();
return $addr->save();
}