|
2 | 2 |
|
3 | 3 | try { |
4 | 4 |
|
5 | | - $config = new Phalcon_Config(array( |
6 | | - 'database' => array( |
7 | | - 'adapter' => 'Mysql', |
8 | | - 'host' => 'localhost', |
9 | | - 'username' => 'test', |
10 | | - 'password' => 'test', |
11 | | - 'name' => 'test_db' |
12 | | - ), |
13 | | - 'phalcon' => array( |
14 | | - 'controllersDir' => '../app/controllers/', |
15 | | - 'modelsDir' => '../app/models/', |
16 | | - 'viewsDir' => '../app/views/' |
17 | | - ) |
18 | | - )); |
| 5 | + //Register an autoloader |
| 6 | + $loader = new \Phalcon\Loader(); |
| 7 | + $loader->registerDirs( |
| 8 | + array( |
| 9 | + '../app/controllers/', |
| 10 | + '../app/models/' |
| 11 | + ) |
| 12 | + )->register(); |
19 | 13 |
|
20 | | - $front = Phalcon_Controller_Front::getInstance(); |
21 | | - $front->setConfig($config); |
22 | | - echo $front->dispatchLoop()->getContent(); |
| 14 | + //Create a DI |
| 15 | + $di = new Phalcon\DI\FactoryDefault(); |
23 | 16 |
|
24 | | -} |
25 | | -catch(Phalcon_Exception $e){ |
26 | | - echo 'PhalconException: '.$e->getMessage(), PHP_EOL; |
27 | | -} |
| 17 | + //Set the database service |
| 18 | + $di->set('db', function(){ |
| 19 | + return new \Phalcon\Db\Adapter\Pdo\Mysql(array( |
| 20 | + "host" => "localhost", |
| 21 | + "username" => "root", |
| 22 | + "password" => "secret", |
| 23 | + "dbname" => "test_db" |
| 24 | + )); |
| 25 | + }); |
| 26 | + |
| 27 | + //Setting up the view component |
| 28 | + $di->set('view', function(){ |
| 29 | + $view = new \Phalcon\Mvc\View(); |
| 30 | + $view->setViewsDir('../app/views/'); |
| 31 | + return $view; |
| 32 | + }); |
28 | 33 |
|
| 34 | + //Handle the request |
| 35 | + $application = new \Phalcon\Mvc\Application(); |
| 36 | + $application->setDI($di); |
| 37 | + echo $application->handle()->getContent(); |
| 38 | + |
| 39 | +} catch(\Phalcon\Exception $e) { |
| 40 | + echo "PhalconException: ", $e->getMessage(); |
| 41 | +} |
0 commit comments