/** * @inheritdoc */ public function run() { $class = $this->model; /** @var CommentModel $classModel */ $classModel = CommentModel::findIdentity($class::className()); if ($classModel) { $model = new Comment(['scenario' => 'create']); $model->model_id = $this->model->id; // NewsPost->id, Page->id $model->model_class = $classModel->id; // crc32(NewsPost::class), crc32(Page::class) $models = Comment::getTree($model->model_id, $model->model_class); return $this->render('index', ['models' => $models, 'model' => $model, 'route' => $this->route]); } return ''; }
/** * Model ID validation. * * @param string $attribute Attribute name * @param array $params Attribute params * * @return mixed */ public function validateModelId($attribute, $params) { /** @var CommentModel $class */ $class = CommentModel::findIdentity($this->model_class); // find valid owner model class by crc32 summ if ($class === null) { $this->addError($attribute, Module::t('model', 'ERROR_MSG_INVALID_MODEL_ID')); } else { // class name of model comment attached to $model = $class->name; if ($model::find()->andWhere(['id' => $this->model_id])->one() === false) { $this->addError($attribute, Module::t('model', 'ERROR_MSG_INVALID_MODEL_ID')); } } }