Created
March 4, 2013 03:33
-
-
Save dmouse/5079709 to your computer and use it in GitHub Desktop.
Ejemplo de uso de Silex
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
// web/index_dev.php | |
require_once __DIR__.'/../vendor/autoload.php'; | |
//inicio de la aplicación | |
$app = new Silex\Application(); | |
//Index | |
$app->match('/', function () { | |
... | |
}) | |
->bind('home'); // alias para uso interno | |
// mipage.com/contact | |
$app->match('/contact', function () { | |
... | |
}); | |
// acceso a /contact_send solo por metodo POST | |
$app->match('/contact_send', function () { | |
... | |
}) | |
->method('POST'); | |
//rutas dinamicas | |
$app->get('/blog/{id}', function ($id) { | |
... | |
}); | |
// multiple paso de variables | |
$app->get('/blog/{postId}/{commentId}', function ($commentId, $postId) { | |
... | |
}); | |
// manejo de json | |
$app->get('/my_porn/{id}', function ($id) use ($app) { | |
$porn = getPorn($id); | |
if (!$porn) { | |
$error = array('message' => 'Noooooooooooooo'); | |
return $app->json($error, 404); | |
} | |
return $app->json($porn); | |
}); | |
// para uso en desarrollo | |
$app['debug'] = true; | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment