Пример #1
0
 /**
  * Sets the subject model
  *
  * @param \yii\db\ActiveRecord $subject
  */
 public function setSubject($subject)
 {
     //validate subject model
     ComponentConfig::isActiveRecord($subject, true);
     ComponentConfig::hasBehavior($subject, CommentsBehavior::className(), true);
     //only on unsaved comments
     if (!$this->isNewRecord) {
         $msg = Yii::t('app', 'The subject model can only be set manually on unsaved comments');
         throw new InvalidCallException($msg);
     }
     //set values from subject model
     $this->model_class = $subject->className();
     $this->foreign_pk = PrimaryKey::asJson($subject);
     $this->subject = $subject;
 }
Пример #2
0
 /**
  * Creates the json-representation of the pk (array in the format attribute=>value)
  * @see \asinfotrack\yii2\toolbox\helpers\PrimaryKey::asJson()
  *
  * @param \yii\db\ActiveRecord $model the model to create the pk for
  * @return string json-representation of the pk-array
  */
 protected static function createPrimaryKeyJson($model)
 {
     return PrimaryKey::asJson($model);
 }
 /**
  * Creates the json-representation of the pk (array in the format attribute=>value)
  * @see \asinfotrack\yii2\toolbox\helpers\PrimaryKey::asJson()
  *
  * @return string json-representation of the pk-array
  * @throws \yii\base\InvalidParamException if the model is not of type ActiveRecord
  * @throws \yii\base\InvalidConfigException if the models pk is empty or invalid
  */
 protected function createPrimaryKeyJson()
 {
     return PrimaryKey::asJson($this->owner);
 }