From 73c9d832809e85cb964418c406e0cb6c6d166143 Mon Sep 17 00:00:00 2001 From: Sid Roberts Date: Sat, 10 Sep 2016 15:48:21 +0100 Subject: [PATCH 1/2] Updated index.php to reflect documentation. --- public/index.php | 91 +++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/public/index.php b/public/index.php index 296a030..8bf296e 100755 --- a/public/index.php +++ b/public/index.php @@ -1,61 +1,64 @@ registerDirs( - array( - '../app/controllers/', - '../app/models/' - ) - )->register(); - - // Create a DI - $di = new FactoryDefault(); - - // Set the database service - $di['db'] = function() { - return new DbAdapter(array( - "host" => "localhost", - "username" => "root", - "password" => "secret", - "dbname" => "tutorial" - )); - }; - - // Setting up the view component - $di['view'] = function() { + +// Register an autoloader +$loader = new Loader(); + +$loader->registerDirs( + [ + "../app/controllers/", + "../app/models/", + ] +); + +$loader->register(); + + + +// Create a DI +$di = new FactoryDefault(); + +// Setup the view component +$di->set( + "view", + function () { $view = new View(); - $view->setViewsDir('../app/views/'); + + $view->setViewsDir("../app/views/"); + return $view; - }; + } +); + +// Setup a base URI so that all generated URIs include the "tutorial" folder +$di->set( + "url", + function () { + $url = new UrlProvider(); + + $url->setBaseUri("/tutorial/"); - // Setup a base URI so that all generated URIs include the "tutorial" folder - $di['url'] = function() { - $url = new Url(); - $url->setBaseUri('/tutorial/'); return $url; - }; + } +); - // Setup the tag helpers - $di['tag'] = function() { - return new Tag(); - }; - // Handle the request - $application = new Application($di); - echo $application->handle()->getContent(); +$application = new Application($di); + +try { + // Handle the request + $response = $application->handle(); -} catch (Exception $e) { - echo "Exception: ", $e->getMessage(); + $response->send(); +} catch (\Exception $e) { + echo "Exception: ", $e->getMessage(); } From 0c0ef31c2276aa38e6fb76c626dc4590f5e4e724 Mon Sep 17 00:00:00 2001 From: Paul Scarrone Date: Sun, 13 Aug 2017 16:58:05 -0400 Subject: [PATCH 2/2] Update index.php --- public/index.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/index.php b/public/index.php index f0033b6..30b2a3d 100755 --- a/public/index.php +++ b/public/index.php @@ -1,11 +1,11 @@ setBaseUri('/'); return $url; };