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

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -