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 -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -