Skip to content

Instantly share code, notes, and snippets.

@AD7six

AD7six/index.php Secret

Created August 17, 2011 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AD7six/d695da6bc429a1ffcd9e to your computer and use it in GitHub Desktop.
Save AD7six/d695da6bc429a1ffcd9e to your computer and use it in GitHub Desktop.
<?php
require_once __DIR__.'/../silex.phar';
use \Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
$mounted = new Silex\Application();
$mounted->get('/', function () use ($mounted) {
echo "{get: true}";
die;
});
$mounted->post('/', function () use ($mounted) {
echo "{post: true}";
die;
});
$mounted->delete('/', function () use ($mounted) {
echo "{delete: true}";
die;
});
$app->mount('/mounted', $mounted);
$app->get('/', function () use ($app) {
$html = <<<INDEX
<head>
</head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
<script>
$.get('/not_mounted', function(resp) { console.log(resp); });
$.ajax({
type: "DELETE",
url: '/not_mounted',
data: true,
success: function(resp) { console.log(resp); }
});
$.post('/not_mounted', {'foo': 'bar123'}, function(resp) { console.log(resp); });
$.get('/mounted', function(resp) { console.log(resp); });
$.ajax({
type: "DELETE",
url: '/mounted',
data: true,
success: function(resp) { console.log(resp); }
});
$.post('/mounted', {'foo': 'bar123'}, function(resp) { console.log(resp); });
</script>
</body>
</html>
INDEX;
return new Response(
$html,
200,
array('Content-Type' => 'text/html')
);
});
$app->get('/not_mounted', function () use ($app) {
echo "{get: true}";
die;
});
$app->post('/not_mounted', function () use ($app) {
echo "{post: true}";
die;
});
$app->delete('/not_mounted', function () use ($app) {
echo "{delete: true}";
die;
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment