|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | use Phalcon\Loader; |
4 | | -use Phalcon\Tag; |
5 | | -use Phalcon\Mvc\Url; |
6 | 4 | use Phalcon\Mvc\View; |
7 | 5 | use Phalcon\Mvc\Application; |
8 | | -use Phalcon\DI\FactoryDefault; |
| 6 | +use Phalcon\Di\FactoryDefault; |
| 7 | +use Phalcon\Mvc\Url as UrlProvider; |
9 | 8 | use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter; |
10 | 9 |
|
11 | | -try { |
12 | 10 |
|
13 | | - // Register an autoloader |
14 | | - $loader = new Loader(); |
15 | | - $loader->registerDirs( |
16 | | - array( |
17 | | - '../app/controllers/', |
18 | | - '../app/models/' |
19 | | - ) |
20 | | - )->register(); |
21 | | - |
22 | | - // Create a DI |
23 | | - $di = new FactoryDefault(); |
24 | | - |
25 | | - // Set the database service |
26 | | - $di['db'] = function() { |
27 | | - return new DbAdapter(array( |
28 | | - "host" => "localhost", |
29 | | - "username" => "root", |
30 | | - "password" => "secret", |
31 | | - "dbname" => "tutorial" |
32 | | - )); |
33 | | - }; |
34 | | - |
35 | | - // Setting up the view component |
36 | | - $di['view'] = function() { |
| 11 | + |
| 12 | +// Register an autoloader |
| 13 | +$loader = new Loader(); |
| 14 | + |
| 15 | +$loader->registerDirs( |
| 16 | + [ |
| 17 | + "../app/controllers/", |
| 18 | + "../app/models/", |
| 19 | + ] |
| 20 | +); |
| 21 | + |
| 22 | +$loader->register(); |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +// Create a DI |
| 27 | +$di = new FactoryDefault(); |
| 28 | + |
| 29 | +// Setup the view component |
| 30 | +$di->set( |
| 31 | + "view", |
| 32 | + function () { |
37 | 33 | $view = new View(); |
38 | | - $view->setViewsDir('../app/views/'); |
| 34 | + |
| 35 | + $view->setViewsDir("../app/views/"); |
| 36 | + |
39 | 37 | return $view; |
40 | | - }; |
| 38 | + } |
| 39 | +); |
| 40 | + |
| 41 | +// Setup a base URI so that all generated URIs include the "tutorial" folder |
| 42 | +$di->set( |
| 43 | + "url", |
| 44 | + function () { |
| 45 | + $url = new UrlProvider(); |
| 46 | + |
| 47 | + $url->setBaseUri("/tutorial/"); |
41 | 48 |
|
42 | | - // Setup a base URI so that all generated URIs include the "tutorial" folder |
43 | | - $di['url'] = function() { |
44 | | - $url = new Url(); |
45 | | - $url->setBaseUri('/tutorial/'); |
46 | 49 | return $url; |
47 | | - }; |
| 50 | + } |
| 51 | +); |
48 | 52 |
|
49 | | - // Setup the tag helpers |
50 | | - $di['tag'] = function() { |
51 | | - return new Tag(); |
52 | | - }; |
53 | 53 |
|
54 | | - // Handle the request |
55 | | - $application = new Application($di); |
56 | 54 |
|
57 | | - echo $application->handle()->getContent(); |
| 55 | +$application = new Application($di); |
| 56 | + |
| 57 | +try { |
| 58 | + // Handle the request |
| 59 | + $response = $application->handle(); |
58 | 60 |
|
59 | | -} catch (Exception $e) { |
60 | | - echo "Exception: ", $e->getMessage(); |
| 61 | + $response->send(); |
| 62 | +} catch (\Exception $e) { |
| 63 | + echo "Exception: ", $e->getMessage(); |
61 | 64 | } |
0 commit comments