-
-
Save mrspartak/94c70fb83a32a71a39db to your computer and use it in GitHub Desktop.
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
<? | |
define('ROOTDIR', realpath( dirname(__FILE__) . '/../../' ) ); | |
//Register app dirs | |
$loader = new \Phalcon\Loader(); | |
$loader->registerDirs( | |
array( | |
ROOTDIR . 'app/models/', | |
ROOTDIR . 'app/vendor/' | |
) | |
)->register(); | |
//setting up DI | |
$di = new \Phalcon\DI\FactoryDefault(); | |
$di->setShared('session', function() { | |
$session = new Phalcon\Session\Adapter\Files(); | |
$session->start(); | |
return $session; | |
}); | |
$app = new Phalcon\Mvc\Micro(); | |
$app->setDI($di); | |
$eventManager = new Phalcon\Events\Manager(); | |
//Listen all the application events | |
$eventManager->attach('micro', function($event, $app) { | |
if ($event->getType() == 'beforeExecuteRoute') { | |
if($app->session->has("logged_in") !== true) { | |
$app->response->redirect("login"); | |
//return false; | |
} | |
} | |
}); | |
$app->setEventsManager($eventManager); | |
/*$app->before(function() use ($app) { | |
if($app->session->has("logged_in") !== true) { | |
return $app->response->redirect("login"); | |
} | |
});*/ | |
$app->get('/', function () use ($app) { | |
echo '/'; | |
}); | |
$app->get('/login', function () use ($app) { | |
echo '/login'; | |
}); | |
$app->handle(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment