Example #1
0
 public function getControllerConfig()
 {
     return array('factories' => array('Application\\Controller\\Login' => function ($sm) {
         $locator = $sm->getServiceLocator();
         // $logger = $locator->get('Zend\Log');
         $controller = new \Application\Controller\LoginController();
         $controller->setLogin($locator->get('Application\\Model\\Login'));
         // $controller->setLogger($logger);
         return $controller;
     }));
 }
Example #2
0
$app->view(new \Slim\Views\Twig());
$app->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath('../templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
$app->view->parserExtensions = array(new \Slim\Views\TwigExtension());
// Define routes
$app->get('/(index)', function () use($app) {
    $app->render('index.html.twig');
});
$app->get('/login', function () use($app) {
    $app->render('login.html.twig');
});
$app->post('/login', function () use($app, $auth) {
    try {
        $username = $app->request()->post('username');
        $password = $app->request()->post('password');
        // TODO: login controller
        $controller = new \Application\Controller\LoginController($app->em);
        $controller->auth($username, $password);
        // register and redirect
        $auth->register($username);
    } catch (Exception $e) {
        $app->view()->set('error', $e->getMessage());
        $app->render('login.html.twig');
    }
});
$app->get('/logout', function () use($app, $auth) {
    $auth->destroy();
    $app->redirect($app->request()->getRootUri() . "/login");
});
// controllers
$app->any('/:controller(/)(:action(/)(:params+))', function ($controller, $action = 'index', $params = array()) use($app) {
    $class = "{$app->controllerNamespace}\\" . ucfirst($controller) . "Controller";