forked from freshteapot/SlimC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
50 lines (44 loc) · 1.44 KB
/
index.php
File metadata and controls
50 lines (44 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
use \SlimC\SlimC;
require __DIR__.'/vendor/autoload.php';
$app = new SlimC(array(
'controller.namespace' => '\\Example\\Controllers',
'templates.path' => 'views'
));
$app->get('/', function() use ($app) {
$url1 = $app->urlFor('ExampleController.getIndex');
$url2 = $app->urlFor('ExampleController.getPage');
$url3 = $app->urlFor('shortname');
$url4 = $app->urlFor('ExampleController.getPageWithVar', array('var' => 'TEST'));
$url5 = $app->urlFor('pageById', array('id' => 10));
$url6 = $app->urlFor('pageById', array('id' => 'wrongid'));
echo 'Try it out: <a href="'.$url1.'">controller root</a> | '
.'<a href="'.$url2.'">controller page</a> | '
.'<a href="'.$url3.'">controller page by shortname</a> | '
.'<a href="'.$url4.'">controller page with a var</a> | '
.'<a href="'.$url5.'">controller page with id (integer)</a> | '
.'<a href="'.$url6.'">controller page with a wrong id</a>'
;
});
$app->controller(
'/example',
'ExampleController',
array(
'GET /' => 'getIndex',
'GET /page' => 'getPage',
'GET /page shortname' => 'getPage',
'GET,POST /page/:var' => 'getPageWithVar',
'GET,POST /pageid/:id pageById' => 'getPageWithVar'
),
array(
"id" => "\d+" //integer validation
)
);
$app->controller(
'/other_example',
'ExampleController',
array(
'GET /' => 'getSecondIndex'
)
);
$app->run();