Skip to content

Instantly share code, notes, and snippets.

@AD7six
Last active August 29, 2015 14:24
Show Gist options
  • Save AD7six/dc17c2e1f7d7c14ecbd4 to your computer and use it in GitHub Desktop.
Save AD7six/dc17c2e1f7d7c14ecbd4 to your computer and use it in GitHub Desktop.
A simple presenter example based on CakePHP 2 code
<?php
class Dummy extends Model {
public function price() {
return (float)1,234.56; // db stored value
}
}
class DummyPresenter {
protected $model;
function __construct(Dummy $modelInstance) {
$this->model = $modelInstance;
}
function price() {
return money_format('%i', $this->model->price()); // the value as it should be shown
}
}
$model = [ find it ];
$presenter = new DummyPresenter($model);
echo $presenter->price(); // USD 1,234.56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment