Skip to content

Instantly share code, notes, and snippets.

@davidreuss
Created June 21, 2013 10:39
Show Gist options
  • Save davidreuss/5830386 to your computer and use it in GitHub Desktop.
Save davidreuss/5830386 to your computer and use it in GitHub Desktop.
Silex controller skeleton
<?php
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
abstract class MyController {
protected $request;
protected $application;
public function __construct(Request $req, Application $app) {
$this->request = $req;
$this->application = $app;
}
public function getApplication() {
return $this->application;
}
public function isPostRequest() {
return strtolower($this->request->getMethod() == 'post');
}
public function getRequest() {
return $this->request;
}
public function willHandleRequest(Silex\Controller $controller) {
$controller->before(function() {
// do stuff
});
}
public function handleRequest() {
// handle the actual request here
}
public function didHandleRequest(Silex\Controller $controller) {
$controller->after(function() {
// do stuff
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment