当前位置: 首页>>代码示例>>PHP>>正文


PHP Behavior::attach方法代码示例

本文整理汇总了PHP中yii\base\Behavior::attach方法的典型用法代码示例。如果您正苦于以下问题:PHP Behavior::attach方法的具体用法?PHP Behavior::attach怎么用?PHP Behavior::attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\base\Behavior的用法示例。


在下文中一共展示了Behavior::attach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: attach

 public function attach($owner)
 {
     parent::attach($owner);
     $owner->on(BaseActiveRecord::EVENT_BEFORE_INSERT, [ClearCacheEvent::className(), ClearCacheEvent::EVENT_CLEAR_CACHE]);
     $owner->on(BaseActiveRecord::EVENT_BEFORE_UPDATE, [ClearCacheEvent::className(), ClearCacheEvent::EVENT_CLEAR_CACHE]);
     $owner->on(BaseActiveRecord::EVENT_BEFORE_DELETE, [ClearCacheEvent::className(), ClearCacheEvent::EVENT_CLEAR_CACHE]);
 }
开发者ID:radiata-cms,项目名称:radiata,代码行数:7,代码来源:CacheBehavior.php

示例2: attach

 /**
  * @inheritdoc
  * @param Controller $owner
  */
 public function attach($owner)
 {
     if (false === $owner instanceof Controller) {
         throw new InvalidParamException('QueryLanguageBehaviour can only be attached to ' . 'instances of Controller');
     }
     parent::attach($owner);
 }
开发者ID:opus-online,项目名称:yii2-base,代码行数:11,代码来源:QueryLanguageBehavior.php

示例3: attach

 public function attach($owner)
 {
     parent::attach($owner);
     if (!$this->key) {
         $this->key = constant(get_class($owner) . '::CACHE_KEY');
     }
 }
开发者ID:radiegtya,项目名称:easyii,代码行数:7,代码来源:CacheFlush.php

示例4: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $validators = $this->owner->getValidators();
     $validator = Validator::createValidator('safe', $this->owner, 'template_id');
     $validators->append($validator);
 }
开发者ID:manyoubaby123,项目名称:imshop,代码行数:10,代码来源:TemplateBehavior.php

示例5: attach

 /**
  * @inheritdoc
  * @param ActiveRecord $owner
  */
 public function attach($owner)
 {
     if (false === $owner instanceof ActiveRecord) {
         throw new InvalidParamException('SafeSaver can only be attached to ' . 'instances of ActiveRecord');
     }
     parent::attach($owner);
 }
开发者ID:opus-online,项目名称:yii2-base,代码行数:11,代码来源:SafeSaverBehaviour.php

示例6: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $validators = $owner->validators;
     foreach ($this->rules as $rule) {
         if ($rule instanceof Validator) {
             $validators->append($rule);
             $this->validators[] = $rule;
             // keep a reference in behavior
         } elseif (is_array($rule) && isset($rule[0], $rule[1])) {
             // attributes, validator type
             $validator = Validator::createValidator($rule[1], $owner, (array) $rule[0], array_slice($rule, 2));
             $validators->append($validator);
             $this->validators[] = $validator;
             // keep a reference in behavior
         } else {
             throw new InvalidConfigException('Invalid validation rule: a rule must specify both attribute names and validator type.');
         }
     }
     $owner->on(ActiveRecord::EVENT_BEFORE_INSERT, function () {
         $this->saveRelatedDir($this->txt, $this->id_field, $this->name_field, $this->classDir);
     });
     $owner->on(ActiveRecord::EVENT_BEFORE_UPDATE, function () {
         $this->saveRelatedDir($this->txt, $this->id_field, $this->name_field, $this->classDir);
     });
 }
开发者ID:slavam,项目名称:placement,代码行数:29,代码来源:BasicBehavior.php

示例7: attach

 public function attach($owner)
 {
     parent::attach($owner);
     if ($this->hasMethod('defaultScope')) {
         call_user_func([$owner->modelClass, 'defaultScope'], $owner);
     }
 }
开发者ID:mdmsoft,项目名称:yii2-ar-behaviors,代码行数:7,代码来源:QueryScopeBehavior.php

示例8: attach

 /**
  * @param ActiveRecord $owner
  */
 public function attach($owner)
 {
     parent::attach($owner);
     // Применяем конфигурационные опции
     foreach ($this->imageConfig as $key => $value) {
         $var = '_' . $key;
         $this->{$var} = $value;
     }
     // Вычисляем корень сайта
     if (empty($this->_rootPathAlias)) {
         $savePathParts = explode('/', $this->_savePathAlias);
         // Удаляем последнюю часть
         unset($savePathParts[count($savePathParts - 1)]);
         // Объединяем все части обратно
         $this->_rootPathAlias = implode('/', $savePathParts);
     }
     // Добавляем валидатор require
     if ($this->_imageRequire) {
         $owner->validators->append(Validator::createValidator(RequiredValidator::className(), $owner, $this->_imageAttribute));
     }
     // Подключаем валидатор изображения
     $validatorParams = array_merge(['extensions' => $this->_fileTypes, 'maxSize' => $this->_maxFileSize, 'skipOnEmpty' => true, 'tooBig' => 'Изображение слишком велико, максимальный размер: ' . floor($this->_maxFileSize / 1024 / 1024) . ' Мб'], $this->_imageValidatorParams);
     $validator = Validator::createValidator(ImageValidator::className(), $owner, $this->_imageAttribute, $validatorParams);
     $owner->validators->append($validator);
 }
开发者ID:tamvodopad,项目名称:yii2-image-uploader,代码行数:28,代码来源:ImageUploaderBehavior.php

示例9: attach

 /**
  * @param ActiveRecord $owner
  */
 public function attach($owner)
 {
     if (!$owner instanceof ActiveRecord) {
         throw new \InvalidArgumentException(sprintf('Behavior %s can only be attached to an instace of yii\\db\\ActiveRecord, %s given.', get_called_class(), is_object($owner) ? get_class($owner) : gettype($owner)));
     }
     parent::attach($owner);
 }
开发者ID:phtamas,项目名称:yii2-sortable,代码行数:10,代码来源:Behavior.php

示例10: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     if (!in_array($owner->scenario, $this->scenarios)) {
         return;
     }
     if (!$owner instanceof PasswordInterface) {
         throw new InvalidConfigException('Class `' . get_class($owner) . '` must be an object implementing ' . '`PasswordInterface`');
     }
     parent::attach($owner);
     $oldPasswordAttribute = $this->oldPasswordAttribute;
     $newPasswordAttribute = $this->newPasswordAttribute;
     $confirmedPasswordAttribute = $this->confirmedPasswordAttribute;
     // required
     if (!$this->skipOnEmpty && !$this->checkPassword) {
         $validator = Validator::createValidator('required', $owner, [$newPasswordAttribute, $confirmedPasswordAttribute]);
         $owner->validators->append($validator);
     }
     // safe
     $attributes = [$newPasswordAttribute, $confirmedPasswordAttribute];
     if ($this->checkPassword) {
         $attributes[] = $oldPasswordAttribute;
     }
     $validator = Validator::createValidator('safe', $owner, $attributes);
     $owner->validators->append($validator);
 }
开发者ID:bupy7,项目名称:yii2-password-behavior,代码行数:28,代码来源:PasswordBehavior.php

示例11: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     if ($this->modelClass === null) {
         $this->modelClass = get_class($owner);
     }
     parent::attach($owner);
 }
开发者ID:netis-pl,项目名称:yii2-relauth,代码行数:10,代码来源:AuthorizerBehavior.php

示例12: attach

 /**
  * Check if the behavior is attached to an Active Record
  * @param ActiveRecord $owner
  * @throws RuntimeException
  */
 public function attach($owner)
 {
     if (!$owner instanceof ActiveRecord) {
         throw new RuntimeException('Owner must be instance of yii\\db\\ActiveRecord');
     }
     parent::attach($owner);
 }
开发者ID:la-haute-societe,项目名称:yii2-save-relations-behavior,代码行数:12,代码来源:SaveRelationsBehavior.php

示例13: attach

 public function attach($model)
 {
     parent::attach($model);
     if (empty($this->fileInputName)) {
         $this->fileInputName = 'hydra_' . $this->attribute;
     }
 }
开发者ID:zabachok,项目名称:yii2-hydra,代码行数:7,代码来源:FileInput.php

示例14: 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);
 }
开发者ID:Liv1020,项目名称:cms,代码行数:11,代码来源:ActiveRecord.php

示例15: attach

 /**
  * @inheritdoc
  */
 public function attach($owner)
 {
     parent::attach($owner);
     $validators = $owner->validators;
     $validator = Validator::createValidator('safe', $owner, array_keys($this->attributes));
     $validators->append($validator);
 }
开发者ID:Mirocow,项目名称:yii2-flag-behavior,代码行数:10,代码来源:FlagBehavior.php


注:本文中的yii\base\Behavior::attach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。