Download the PHP package warrickbayman/looker without Composer
On this page you can find all versions of the php package warrickbayman/looker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download warrickbayman/looker
More information about warrickbayman/looker
Files in warrickbayman/looker
Package looker
Short Description A really simple PHP view presenter based on Jeffery Ways laracasts\Presenter class
License MIT
Informations about the package looker
Looker
A simple PHP presenter library.
Why
Well, it's quite common to separate your presentation code from your models. When I started with PHP I found myself doing things like:
This is bad. So Looker separates your presentation stuff out of your models. It's based on the simple presentation library that Jeffery Way wrote for Laracasts.
Installation
Use composer:
Usage
In your model add the Looker\Presentable
trait:
Create a new view presenter that extends the Looker\Presenter
class
Now, in your view:
From within the presenter, $this->entity
is the associated model.
By default, Looker will look in the Http\Presenters
namespace for presenter classes, but you can change that. Somewhere in your intialization, call the Looker::init
method and pass in the class path for your presenters:
You can also pass in a "suffix" if you like to do things like add the word "Presenter" to the end of your presenter classes:
Now Looker will look for UserPresenter
instead of just User
.
Overriding Model Members
Looker will automatically override model members. So you can do:
even if the dateOfBirth
method or property doesn't exist on your presenter. Looker will first look for a method by the same name on the model. If a method doesn't exist, it will then look for a property by the same name. Looker will throw a OverrideFailed
exception if there is no method or property to call.