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