Skip to content

Commit a2d3b15

Browse files
committed
updating for v5.0
1 parent 8c3b89f commit a2d3b15

File tree

9 files changed

+99
-70
lines changed

9 files changed

+99
-70
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ performance and lower resource consumption.
55

66
This is a very simple tutorial to understand the basis of work with Phalcon.
77

8-
Check out a [explanation article][1].
8+
Check out an [explanation article][1].
99

1010
## Get Started
1111

1212
### Requirements
1313

1414
To run this application on your machine, you need at least:
1515

16-
* PHP >= 7+
16+
* PHP >= 8.0+
1717
* Server Any of the following
1818
* [Apache][2] Web Server with [mod_rewrite][3] enabled
1919
* [Nginx][4] Web Server
@@ -22,6 +22,7 @@ To run this application on your machine, you need at least:
2222
You can also run the application using [nanobox.io][8]. Installation instructions for nanobox can be found [here][9].
2323

2424
## Running the application
25+
2526
* Clone the repository to a folder on your machine
2627
* Navigate to that folder
2728
* Run `nanobox run`
@@ -30,14 +31,23 @@ You can also run the application using [nanobox.io][8]. Installation instruction
3031

3132
## License
3233

33-
Phalcon Tutorial is open-sourced software licensed under the [New BSD License][6]. © Phalcon Framework Team and contributors
34+
Phalcon Tutorial is open-sourced software licensed under the [New BSD License][6]. © Phalcon Framework Team and
35+
contributors
3436

3537
[1]: https://docs.phalcon.io/latest/en/tutorial-basic
38+
3639
[2]: http://httpd.apache.org/
40+
3741
[3]: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
42+
3843
[4]: http://nginx.org/
44+
3945
[5]: https://github.com/phalcon/cphalcon/releases
46+
4047
[6]: https://github.com/phalcon/tutorial/blob/master/docs/LICENSE.md
48+
4149
[7]: https://github.com/phalcon/phalcon-devtools
50+
4251
[8]: https://nanobox.io
52+
4353
[9]: https://docs.nanobox.io/install/

app/controllers/SignupController.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@ public function indexAction()
1616
*/
1717
public function registerAction()
1818
{
19-
$user = new Users();
19+
$post = $this->request->getPost();
2020

2121
// Store and check for errors
22-
$success = $user->save(
23-
$this->request->getPost(),
24-
['name', 'email']
25-
);
22+
$user = new Users();
23+
$user->name = $post['name'];
24+
$user->email = $post['email'];
25+
// Store and check for errors
26+
$success = $user->save();
2627

2728
// passing the result to the view
2829
$this->view->success = $success;
2930

3031
if ($success) {
3132
$message = "Thanks for registering!";
3233
} else {
33-
$message = "Sorry, the following problems were generated:<br>" . implode('<br>', $user->getMessages());
34+
$message = "Sorry, the following problems were generated:<br>"
35+
. implode('<br>', $user->getMessages());
3436
}
3537

3638
// passing a message to the view

app/views/index/index.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
echo "<h1>Hello!</h1>";
44

5-
echo $this->tag->linkTo(["signup", "Sign Up Here!", 'class' => 'btn btn-primary']);
5+
echo $this->tag->a('signup', 'Sign Up Here!', ['class' => 'btn btn-primary']);
66

77
if ($users->count() > 0) {
88
?>
@@ -30,4 +30,4 @@ if ($users->count() > 0) {
3030
</tbody>
3131
</table>
3232
<?php
33-
}
33+
}

app/views/signup/index.phtml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<h2>Sign using this form</h2>
22

3-
<?php echo $this->tag->form('signup/register') ?>
3+
<?php echo $this->tag->form(['action' => '/signup/register']); ?>
44

55
<p>
66
<label for="name">Name</label>
7-
<?php echo $this->tag->textField("name") ?>
7+
<?php echo $this->tag->inputText('name'); ?>
88
</p>
99

1010
<p>
1111
<label for="name">E-Mail</label>
12-
<?php echo $this->tag->textField("email") ?>
12+
<?php echo $this->tag->inputText('email'); ?>
1313
</p>
1414

1515
<p>
16-
<?php echo $this->tag->submitButton(["Register", 'class' => 'btn btn-primary']) ?>
16+
<?php echo $this->tag->inputSubmit('Register', null, ['class' => 'btn btn-primary']); ?>
1717
</p>
1818

19-
<?php echo $this->tag->endForm() ?>
19+
<?php echo $this->tag->close('form'); ?>
20+

app/views/signup/register.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<?php echo $message; ?>
33
</div>
44

5-
<?php echo $this->tag->linkTo(['/', 'Go back', 'class' => 'btn btn-primary']); ?>
5+
<?php echo $this->tag->a('/', 'Go back', ['class' => 'btn btn-primary']); ?>

boxfile.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

docs/LICENSE.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ New BSD License
44
Copyright (c) 2013-2017, Phalcon Framework Team and contributors
55
All rights reserved.
66

7-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
8+
following conditions are met:
89

9-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11-
* Neither the name of the <organization> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following
11+
disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided with the distribution.
14+
* Neither the name of the <organization> nor the names of its contributors may be used to endorse or promote products
15+
derived from this software without specific prior written permission.
1216

13-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23+
POSSIBILITY OF SUCH DAMAGE.

public/index.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3+
use Phalcon\Autoload\Loader;
34
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
45
use Phalcon\Di\FactoryDefault;
5-
use Phalcon\Loader;
66
use Phalcon\Mvc\Application;
77
use Phalcon\Mvc\Url as UrlProvider;
88
use Phalcon\Mvc\View;
@@ -12,44 +12,47 @@
1212

1313
// Register an autoloader
1414
$loader = new Loader();
15-
$loader->registerDirs(
15+
$loader->setDirectories(
1616
[
1717
APP_PATH . '/controllers/',
1818
APP_PATH . '/models/',
1919
]
20-
)->register();
20+
)
21+
->register()
22+
;
2123

2224
// Create a DI
23-
$di = new FactoryDefault();
25+
$container = new FactoryDefault();
2426

2527
// Setting up the view component
26-
$di['view'] = function () {
28+
$container['view'] = function () {
2729
$view = new View();
2830
$view->setViewsDir(APP_PATH . '/views/');
2931
return $view;
3032
};
3133

3234
// Setup a base URI so that all generated URIs include the "tutorial" folder
33-
$di['url'] = function () {
35+
$container['url'] = function () {
3436
$url = new UrlProvider();
3537
$url->setBaseUri('/');
3638
return $url;
3739
};
3840

3941
// Set the database service
40-
$di['db'] = function () {
42+
$container['db'] = function () {
4143
return new DbAdapter([
42-
"host" => getenv('DATA_MYSQL_HOST'),
43-
"username" => getenv('DATA_MYSQL_USER'),
44-
"password" => getenv('DATA_MYSQL_PASS'),
45-
"dbname" => "gonano",
44+
"host" => 'localhost',
45+
"username" => 'your_db_user_name',
46+
"password" => 'your_db_password',
47+
"dbname" => 'tutorial',
4648
]);
4749
};
4850

4951
// Handle the request
5052
try {
51-
$application = new Application($di);
52-
echo $application->handle()->getContent();
53+
$application = new Phalcon\Mvc\Application($container);
54+
$response = $application->handle($_SERVER["REQUEST_URI"]);
55+
$response->send();
5356
} catch (Exception $e) {
5457
echo "Exception: ", $e->getMessage();
5558
}

storage/schemas/tutorial.sql

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
1-
DROP TABLE IF EXISTS `users`;
2-
CREATE TABLE `users` (
3-
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
4-
`name` varchar(70) NOT NULL,
5-
`email` varchar(70) NOT NULL,
1+
CREATE DATABASE IF NOT EXISTS `tutorial` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
2+
USE `tutorial`;
63

4+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
5+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
6+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
7+
/*!40101 SET NAMES utf8mb4 */;
8+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
9+
/*!40103 SET TIME_ZONE='+00:00' */;
10+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
11+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
12+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
13+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
14+
15+
--
16+
-- Table structure for table `users`
17+
--
18+
19+
/*!40101 SET @saved_cs_client = @@character_set_client */;
20+
/*!40101 SET character_set_client = utf8mb4 */;
21+
CREATE TABLE `users`
22+
(
23+
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Record ID',
24+
`name` varchar(255) NOT NULL COMMENT 'User Name',
25+
`email` varchar(255) NOT NULL COMMENT 'User Email Address',
726
PRIMARY KEY (`id`)
8-
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
27+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
28+
29+
/*!40101 SET character_set_client = @saved_cs_client */;
30+
31+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
32+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
33+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
34+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
35+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
36+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
37+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
38+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
939

10-
INSERT INTO `users` (`name`, `email`) VALUES ('Phalcon Team', '[email protected]');
40+
INSERT INTO `users` (`name`, `email`)
41+
VALUES ('Phalcon Team', '[email protected]');

0 commit comments

Comments
 (0)