yii2 - Class name dynamically in hasOne not working -
public function getresource() { return $this->hasone(user::classname(), ['id' => 'resource_id']); }
this function working fine when use this
public function getresource() { $model = ucfirst($this->resource_type); return $this->hasone($model::classname(), ['id' => 'resource_id']); }
its give me error "class 'user' not found". thanks
you have use name including namespace if specify dynamically.
public function getresource() { $model = "api\\models\\".ucfirst($this->resource_type); return $this->hasone($model::classname(), ['id' => 'resource_id']); }
Comments
Post a Comment