From 4047ca0e1e3c3b3a957f0ac5a6d3924964ebf471 Mon Sep 17 00:00:00 2001 From: Paul Scarrone Date: Sat, 12 Aug 2017 22:42:09 -0400 Subject: [PATCH] Revise tutorial project to match documentation --- .htrouter.php | 29 +++++++++++++ .phalcon/.gitkeep | 0 README.md | 8 +++- app/models/Users.php | 2 - app/views/index/index.phtml | 1 - docs/LICENSE.md | 2 +- docs/LICENSE.txt | 2 +- public/index.php | 86 +++++++++++++++++-------------------- schemas/tutorial.sql | 11 ++--- 9 files changed, 83 insertions(+), 58 deletions(-) create mode 100644 .htrouter.php create mode 100644 .phalcon/.gitkeep diff --git a/.htrouter.php b/.htrouter.php new file mode 100644 index 0000000..effc318 --- /dev/null +++ b/.htrouter.php @@ -0,0 +1,29 @@ + | + | Eduar Carvajal | + | Serghei Iakovlev | + +------------------------------------------------------------------------+ +*/ + +define('PUBLIC_PATH', __DIR__ . '/public'); + +$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); +if ($uri !== '/' && file_exists(PUBLIC_PATH . $uri)) { + return false; +} +$_GET['_url'] = $_SERVER['REQUEST_URI']; + +require_once PUBLIC_PATH . '/index.php'; diff --git a/.phalcon/.gitkeep b/.phalcon/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 1f9666b..df79eb5 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,20 @@ Check out a [explanation article][1]. To run this application on your machine, you need at least: * PHP >= 5.4 -* [Apache][2] Web Server with [mod_rewrite][3] enabled or [Nginx][4] Web Server +* Server Any of the following + * [Phalcon Devtools][7] using provided **.htrouter** and `phalcon serve` command + * [Apache][2] Web Server with [mod_rewrite][3] enabled + * [Nginx][4] Web Server * Latest stable [Phalcon Framework release][5] extension enabled ## License Phalcon Tutorial is open-sourced software licensed under the [New BSD License][6]. © Phalcon Framework Team and contributors -[1]: http://docs.phalconphp.com/en/latest/reference/tutorial.html +[1]: https://docs.phalconphp.com/en/latest/tutorial-base [2]: http://httpd.apache.org/ [3]: http://httpd.apache.org/docs/current/mod/mod_rewrite.html [4]: http://nginx.org/ [5]: https://github.com/phalcon/cphalcon/releases [6]: https://github.com/phalcon/tutorial/blob/master/docs/LICENSE.md +[7]: https://github.com/phalcon/phalcon-devtools diff --git a/app/models/Users.php b/app/models/Users.php index 7e9e3f4..287e26a 100644 --- a/app/models/Users.php +++ b/app/models/Users.php @@ -6,9 +6,7 @@ class Users extends Model { public $id; - public $name; - public $email; } diff --git a/app/views/index/index.phtml b/app/views/index/index.phtml index 1882ce8..d485dbc 100644 --- a/app/views/index/index.phtml +++ b/app/views/index/index.phtml @@ -3,4 +3,3 @@ echo "

Hello!

"; echo $this->tag->linkTo("signup", "Sign Up Here!"); - diff --git a/docs/LICENSE.md b/docs/LICENSE.md index bfc6075..28fa8fa 100644 --- a/docs/LICENSE.md +++ b/docs/LICENSE.md @@ -1,7 +1,7 @@ New BSD License =============== -Copyright (c) 2013-2015, Phalcon Framework Team and contributors +Copyright (c) 2013-2017, Phalcon Framework Team and contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/docs/LICENSE.txt b/docs/LICENSE.txt index 2232f8e..7d5e552 100644 --- a/docs/LICENSE.txt +++ b/docs/LICENSE.txt @@ -1,6 +1,6 @@ New BSD License -Copyright (c) 2013-2015, Phalcon Framework Team and contributors +Copyright (c) 2013-2017, Phalcon Framework Team and contributors All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/public/index.php b/public/index.php index 296a030..22a4d75 100755 --- a/public/index.php +++ b/public/index.php @@ -1,61 +1,55 @@ registerDirs( + array( + APP_PATH . '/controllers/', + APP_PATH . '/models/' + ) +)->register(); + +// Create a DI +$di = new FactoryDefault(); + +// Setting up the view component +$di['view'] = function() { + $view = new View(); + $view->setViewsDir(APP_PATH . '/views/'); + return $view; +}; + +// Setup a base URI so that all generated URIs include the "tutorial" folder +$di['url'] = function() { + $url = new Url(); + $url->setBaseUri('/'); + return $url; +}; + +// Set the database service +$di['db'] = function() { + return new DbAdapter(array( + "host" => "127.0.0.1", + "username" => "root", + "password" => "secret", + "dbname" => "tutorial1" + )); +}; + +// Handle the request try { - - // Register an autoloader - $loader = new Loader(); - $loader->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() { - $view = new View(); - $view->setViewsDir('../app/views/'); - return $view; - }; - - // 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(); - } catch (Exception $e) { echo "Exception: ", $e->getMessage(); } diff --git a/schemas/tutorial.sql b/schemas/tutorial.sql index 44f6f06..4f41c68 100644 --- a/schemas/tutorial.sql +++ b/schemas/tutorial.sql @@ -1,6 +1,6 @@ -- MySQL dump 10.13 Distrib 5.5.36, for osx10.9 (i386) -- --- Host: localhost Database: tutorial +-- Host: localhost Database: tutorial1 -- ------------------------------------------------------ -- Server version 5.5.36 @@ -23,10 +23,11 @@ DROP TABLE IF EXISTS `users`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `users` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(70) NOT NULL, - `email` varchar(70) NOT NULL, - PRIMARY KEY (`id`) + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(70) NOT NULL, + `email` varchar(70) NOT NULL, + + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */;