Answer the question
In order to leave comments, you need to log in
How to show object property in twig?
The situation is this, before using twig the class looked like this
class User
{
public $data = [];
public function __construct($id)
{
$this->id = $id;
$this->data = $this->getData();
}
private function getData()
{
return [];
}
public function __get($name)
{
if (isset($this->data[$name])) {
return $this->data[$name];
}
}
}
$user = new User(1);
echo $user->first_name;
class User
{
public $data = [];
public $first_name;
public function __construct($id)
{
$this->id = $id;
$this->data = $this->getData();
$this->first_name = $this->data['first_name'];
}
private function getData()
{
return ['first_name' => 'Йаволь'];
}
public function __get($name)
{
if (isset($this->data[$name])) {
return $this->data[$name];
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question