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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -