Presenters in PHP - How to clean your views
Super simple!
class BookPresenter extends Presenter
{
public function __construct(
public Book $book
) {}
public function price()
{
return number_format($this->book->price, 2);
}
}
You can also add it to your model
class Book
{
public function present()
{
return new BookPresenter($this);
}
}
// usage
$book->present()->price();
You can even use a package to supercharge your presenters : https://github.com/jamierumbelow/presenters
I consider myself as an IT Business Artisan. Or Consultant CTO. I'm a self-taught Web Developper, coach and teacher. My main work is helping and guiding digital startups.
more about meBTC
bc1qgw9a8hyqqwvcls9ln7vhql4mad0qkveutr2td7
ETH
0x3A720717Da03dB6f3c4a4Ff08BC64100205A79d0
2025 © My Dynamic Production SRL All rights Reserved.