Skip to content

Commit 73c9d83

Browse files
authored
Updated index.php to reflect documentation.
1 parent 01a8107 commit 73c9d83

File tree

1 file changed

+47
-44
lines changed

1 file changed

+47
-44
lines changed

public/index.php

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,64 @@
11
<?php
22

33
use Phalcon\Loader;
4-
use Phalcon\Tag;
5-
use Phalcon\Mvc\Url;
64
use Phalcon\Mvc\View;
75
use Phalcon\Mvc\Application;
8-
use Phalcon\DI\FactoryDefault;
6+
use Phalcon\Di\FactoryDefault;
7+
use Phalcon\Mvc\Url as UrlProvider;
98
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
109

11-
try {
1210

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 () {
3733
$view = new View();
38-
$view->setViewsDir('../app/views/');
34+
35+
$view->setViewsDir("../app/views/");
36+
3937
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/");
4148

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/');
4649
return $url;
47-
};
50+
}
51+
);
4852

49-
// Setup the tag helpers
50-
$di['tag'] = function() {
51-
return new Tag();
52-
};
5353

54-
// Handle the request
55-
$application = new Application($di);
5654

57-
echo $application->handle()->getContent();
55+
$application = new Application($di);
56+
57+
try {
58+
// Handle the request
59+
$response = $application->handle();
5860

59-
} catch (Exception $e) {
60-
echo "Exception: ", $e->getMessage();
61+
$response->send();
62+
} catch (\Exception $e) {
63+
echo "Exception: ", $e->getMessage();
6164
}

0 commit comments

Comments
 (0)