public static function GETSingle($params, $method, $headers) { $id = Request::requireId($params); $posts = Post::getAll(); array_unshift($posts, []); if ($id == 0 || $id > count($posts) - 1) { throw new \Phramework\Exceptions\NotFoundException('Post not found'); } Phramework::view(['posts' => [$posts[$id]]], 'blog', 'My blog #' . $id); //will load viewers/page/blog.php }
public static function POST($params) { //Define model $model = ['title' => ['type' => Validate::TYPE_TEXT, 'max' => 12, 'min' => 3, Validate::REQUIRED], 'content' => ['type' => Validate::TYPE_TEXT, 'max' => 4096, 'min' => 12, Validate::REQUIRED]]; //Require and Validate model Validate::model($params, $model); //Declare them as variables $title = $params['title']; $content = $params['content']; $post = ['title' => $title, 'content' => $content, 'timestamp' => time()]; $post = \Phramework\Models\Filter::castEntry($post, ['timestamp' => Validate::TYPE_UNIX_TIMESTAMP]); //Store ($title, $content) somehow and get the id $id = rand(0, 100); $post['id'] = $id; \Phramework\Models\Response::created('http://localhost/post/' . $id . '/'); //Sample output Phramework::view(['post' => $post], 'post', 'Blog post'); }
public static function GETById($params, $method, $headers, $id) { \Phramework\Phramework::view(['data' => ['type' => 'dummy', 'id' => $id]]); }
/** * Shortcut to \Phramework\Phramework::view * @param array $params * @uses \Phramework\Phramework::view */ protected static function view($params = []) { \Phramework\Phramework::view($params); }