當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。