Answer the question
In order to leave comments, you need to log in
Who should take on the duty of a helper?
Actually I'm trying to move towards good code and I want to solve the headache with helpers once and for all.
Suppose there is the following situation: You need to render product data in the form.
We have an entity:
class Product {
protected $name;
protected $description;
protected $price;
protected $amount;
public function setName($name)
{
...
}
public function setDescription($description)
{
...
}
public function setPrice($price)
{
...
}
public function setAmount($amount)
{
...
}
public function getName()
{
...
}
public function getDescription()
{
...
}
public function getPrice()
{
...
}
public function getAmount()
{
...
}
}
<p class="price">{{ Currency::formatString($product->getPrice()) }}</p>
<p class="price">{{ $product->getPriceString() }}</p>
Answer the question
In order to leave comments, you need to log in
the data in the model should be as it is, you need to format it at the output level, for
example, there are places where you need to display the date, let’s say in the format dmY H: i and where is dmY, and where in general in Ymd H: i
, you won’t keep 3 methods to display these dates
are better $model->getDateTime()->format("dmY H:i");//where $model->getDateTime() returns a Datetime object
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question