Presenters in PHP - How to clean your views

profile picture

Presenters in PHP - How to clean your views

How to use a Presenter class

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

php
presenter

about me

profile picture

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 me

follow me

newsletter

A weekly email with the latests articles

support my work

Start trading on binance
  • BTC

    BTC

    18SY81ejLGFuJ9KMWQu5zPrDGuR5rDiauM

  • ETH

    ETH

    0x519e0eaa9bc83018bb306880548b79fc0794cd08

  • Monero

    XMR

    895bSneY4eoZjsr2hN2CAALkUrMExHEV5Pbg8TJb6ejnMLN7js1gLAXQySqbSbfzjWHQpQhQpvFtojbkdZQZmM9qCFz7BXU

recent posts

QBUS - MQTT Quick Tutorial

1
10 months ago

DDOS By Web Crawlers

1
1 year ago

Something Given

1
1 year ago

2024 © My Dynamic Production SRL All rights Reserved.