Skip to content

Instantly share code, notes, and snippets.

@jaytaph
Created March 4, 2015 21:08
Show Gist options
  • Save jaytaph/4499b3f23c59a312f467 to your computer and use it in GitHub Desktop.
Save jaytaph/4499b3f23c59a312f467 to your computer and use it in GitHub Desktop.
namespace Application;
class Controller {
protected $app;
function __construct($app) {
$this->app = $app;
}
function getListAction() {
// Doe je ding voor getList
}
function getContactAction() {
// doe je ding voor getContact
}
}
$app = new Silex\Application();
// Doe hier je standaard silex setup
// application.controller service wijst naar je controller class met je acties
$app['application.controller'] = $app->share(function() use ($app) {
return new \Application\Controller($app);
}
// Dit kan een controller met acties zijn voor een gastenboek bijvoorbeeld
$app['guestbook.controller'] = $app->share(function() use ($app) {
// GuestbookController in dezelfde trant als the Controller.php
return new \Application\GuestbookController($app);
}
// get '/' wijst naar de getListAction uit de 'application.controller' service en gebonden aan 'home'
$app->get('/', 'application.controller:getListAction')->bind('home');
// get '/contact' wijst naar de getContactAction uit de 'application.controller' service en gebonden aan 'contact'
$app->get('/contact', 'application.controller:getContactAction')->bind('contact');
// get '/gastenboek' wijst naar de getIndexAction uit de 'guestbook.controller'
$app->get('/guestbook', 'guestbook.getIndexAction')->bind('guestbook');
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment