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

Popular posts from this blog

angular - DownloadURL return null in below code -

python 2.7 - Given three nested dictionaries, sort the top two nested dictionaries from a value in the innermost dictionary? -