Slide 29
Slide 29 text
// models/Posts.php
namespace blog\models;
class Posts extends \lithium\data\Model {
protected $_schema = [
'_id' => ['type' => 'id'],
'author' => ['type' => 'id'],
'title' => ['type' => 'string'],
'body' => ['type' => 'string'],
'tags' => ['type' => 'string', 'array' => true],
'hits' => ['type' => 'integer', 'default' => 0]
];
public $validates = [
'title' => ['notEmpty', 'message' => 'Please to be including a title?'],
'body' => ['notEmpty', 'message' => 'Now you\'re just defeating the purpose']
];
public static function resetHits() {
return static::update(['$set' => ['hits' => 0]], []);
}
public function timestamp($post) {
return $post->_id->getTimestamp();
}
}