承接 warrickbayman/looker 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

warrickbayman/looker

最新稳定版本:1.0.1

Composer 安装命令:

composer require warrickbayman/looker

包简介

A really simple PHP view presenter based on Jeffery Ways laracasts\Presenter class

README 文档

README

Build Status Stable Latest Unstable Version License

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:

//User.php

class User extends Model
{
    public function fullName()
    {
        return $this->first_name . ' ' . $this->last_name;
    }
}

// view.php
<?php echo $user->fullName(); ?>

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:

composer require warrickbayman/looker

Usage

In your model add the Looker\Presentable trait:

use Looker\Traits\Presentable;

class User
{
    use Presentable;
}

Create a new view presenter that extends the Looker\Presenter class

use Looker\Presenter;

class User extends Presenter
{
    public function fullName()
    {
        return $this->entity->first_name . ' ' . $this->entity->last_name;
    }
}

Now, in your view:

echo $this->present()->fullName;

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:

Looker\Looker::init('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:

Looker\Looker::init('Presenters', 'Presenter');

Now Looker will look for UserPresenter instead of just User.

Overriding Model Members

Looker will automatically override model members. So you can do:

echo $user->present()->dateOfBirth;

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.

统计信息

  • 总下载量: 3.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-04