jamierumbelow/presenters 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

jamierumbelow/presenters

最新稳定版本:1.0.0

Composer 安装命令:

composer require jamierumbelow/presenters

包简介

Clean up your views with PHP presenters

README 文档

README

It's very easy to end up with complicated, brittle views full of messy logic and presentation code that really should be somewhere else. In my book, The CodeIgniter Handbook - Volume One - Who Needs Ruby? I discuss a great technique for cleaning up your views.

This small library is a lightweight, tested solution for using presenters within PHP (and CodeIgniter apps). This library is tailored for CI, but works with any PHP application.

Synopsis

class Book_Presenter extends Presenter
{
	public function price()
	{
		return number_format($this->book->price, 2);
	}
}

$book = $this->db->where('id', 1)->get('books')->row();
$book = new Book_Presenter($book);

echo $book->title() . ' costs ' . $book->price();

Installation

Add it to your composer.json:

{
	"require": {
		"jamierumbelow/presenters": "*"
	}
}

Run composer update:

$ php composer.phar update

...and autoload:

require_once 'vendor/autoload.php';

Usage

Create a new class with the suffix _Presenter. Book_presenter will create a $this->book variable, Game_Type_Presenter will create a $this->game_type variable.

Instantiate a new presenter object and pass through the raw object:

$book = $this->db->where('id', 1)->get('books')->row();
$book = new Book_Presenter($book);

You can then access the data inside the presenter:

class Book_Presenter extends Presenter
{
	public function title()
	{
		return $this->book->title . ' - ' . $this->book->subtitle;
	}
}

If you'd like to customise the object name, pass it through as the second parameter:

$book = new Book_Presenter($book, 'bookObject');

class Book_Presenter extends Presenter
{
	public function title()
	{
		return $this->bookObject->title . ' - ' . $this->bookObject->subtitle;
	}
}

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-12-04