Created
November 17, 2012 21:09
-
-
Save DavertMik/4100360 to your computer and use it in GitHub Desktop.
PHP Slices MVC Framework Concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserController extends UserCollection implements Slice\RestController { | |
use \Slice\HttpController; | |
use \Slice\RESTController; | |
use \Slice\Response\ToJson; | |
protected function action($request, $user) | |
{ | |
if ($request->GET('/')) | |
return $this->list($request['offset']); | |
if ($request->GET('/:id')) | |
return $this->fetch($request['id']); | |
if ($request->POST('/') and $user->is('admin')) | |
return [$this->create($request['user']), 'user was sucessfully created')]; | |
return $this->restRoutes($request, $user); | |
} | |
} | |
class ViewUserController extends UserController | |
{ | |
use \Slice\View; | |
function index($request, $user) | |
{ | |
parent::index($request, $user); | |
$theme = $user->session('theme'); | |
return new TwigView('user/index.twig', ['theme' => $theme]); | |
} | |
} | |
class CachedUserController extends UserController | |
{ | |
use \Slice\Cache | |
protected function cache($request, $user) | |
{ | |
if (!$user) $this->setCache('index')->for(86400); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment