Skip to content

Commit 27c4891

Browse files
Updating tutorial
1 parent 66d049d commit 27c4891

7 files changed

Lines changed: 117 additions & 41 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Get Started
1515

1616
To run this application on your machine, you need at least:
1717

18-
* PHP >= 5.3.11
18+
* PHP >= 5.3.21
1919
* Apache Web Server with mod rewrite enabled
20-
* Phalcon Framework extension enabled (>= 0.5.x)
20+
* Phalcon Framework extension enabled (>= 1.3.x)
2121

app/controllers/IndexController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
class IndexController extends Phalcon\Mvc\Controller
3+
use Phalcon\Mvc\Controller;
4+
5+
class IndexController extends Controller
46
{
57

68
public function indexAction()
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
class SignupController extends Phalcon\Mvc\Controller
3+
use Phalcon\Mvc\Controller;
4+
5+
class SignupController extends Controller
46
{
57

68
public function indexAction()
@@ -11,23 +13,24 @@ public function indexAction()
1113
public function registerAction()
1214
{
1315

14-
//Request variables from html form
15-
$name = $this->request->getPost('name', 'string');
16-
$email = $this->request->getPost('email', 'email');
17-
1816
$user = new Users();
19-
$user->name = $name;
20-
$user->email = $email;
2117

22-
//Store and check for errors
23-
if ($user->save() == true) {
24-
echo 'Thanks for register!';
18+
// Store and check for errors
19+
$success = $user->save(
20+
$this->request->getPost(),
21+
array('name', 'email')
22+
);
23+
24+
if ($success) {
25+
echo "Thanks for registering!";
2526
} else {
26-
echo 'Sorry, the next problems were generated: ';
27-
foreach ($user->getMessages() as $message){
28-
echo $message->getMessage(), '<br/>';
27+
echo "Sorry, the following problems were generated: ";
28+
foreach ($user->getMessages() as $message) {
29+
echo $message->getMessage(), "<br/>";
2930
}
3031
}
32+
33+
$this->view->disable();
3134
}
3235

3336
}

app/views/index/index.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

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

5-
echo Phalcon\Tag::linkTo("signup", "Sign Up Here!");
5+
echo $this->tag->linkTo("signup", "Sign Up Here!");
66

app/views/signup/index.phtml

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

3-
<?php echo Phalcon\Tag::form('signup/register') ?>
4-
3+
<?php echo $this->tag->form('signup/register') ?>
4+
55
<p>
66
<label for="name">Name</label>
7-
<?php echo Phalcon\Tag::textField("name") ?>
7+
<?php echo $this->tag->textField("name") ?>
88
</p>
99

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

1515
<p>
16-
<?php echo Phalcon\Tag::submitButton("Register") ?>
16+
<?php echo $this->tag->submitButton("Register") ?>
1717
</p>
1818

1919
</form>

public/index.php

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,61 @@
11
<?php
22

3+
use Phalcon\Loader;
4+
use Phalcon\Tag;
5+
use Phalcon\Mvc\Url;
6+
use Phalcon\Mvc\View;
7+
use Phalcon\Mvc\Application;
8+
use Phalcon\DI\FactoryDefault;
9+
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
10+
311
try {
412

5-
//Register an autoloader
6-
$loader = new \Phalcon\Loader();
13+
// Register an autoloader
14+
$loader = new Loader();
715
$loader->registerDirs(
816
array(
917
'../app/controllers/',
1018
'../app/models/'
1119
)
1220
)->register();
1321

14-
//Create a DI
15-
$di = new Phalcon\DI\FactoryDefault();
22+
// Create a DI
23+
$di = new FactoryDefault();
1624

17-
//Set the database service
18-
$di->set('db', function(){
19-
return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
20-
"host" => "localhost",
25+
// Set the database service
26+
$di['db'] = function() {
27+
return new DbAdapter(array(
28+
"host" => "localhost",
2129
"username" => "root",
2230
"password" => "secret",
23-
"dbname" => "test_db"
31+
"dbname" => "tutorial"
2432
));
25-
});
33+
};
2634

27-
//Setting up the view component
28-
$di->set('view', function(){
29-
$view = new \Phalcon\Mvc\View();
35+
// Setting up the view component
36+
$di['view'] = function() {
37+
$view = new View();
3038
$view->setViewsDir('../app/views/');
3139
return $view;
32-
});
40+
};
41+
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/');
46+
return $url;
47+
};
48+
49+
// Setup the tag helpers
50+
$di['tag'] = function() {
51+
return new Tag();
52+
};
53+
54+
// Handle the request
55+
$application = new Application($di);
3356

34-
//Handle the request
35-
$application = new \Phalcon\Mvc\Application();
36-
$application->setDI($di);
3757
echo $application->handle()->getContent();
3858

39-
} catch(\Phalcon\Exception $e) {
40-
echo "PhalconException: ", $e->getMessage();
59+
} catch (Exception $e) {
60+
echo "Exception: ", $e->getMessage();
4161
}

schemas/tutorial.sql

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- MySQL dump 10.13 Distrib 5.5.36, for osx10.9 (i386)
2+
--
3+
-- Host: localhost Database: tutorial
4+
-- ------------------------------------------------------
5+
-- Server version 5.5.36
6+
7+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10+
/*!40101 SET NAMES utf8 */;
11+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12+
/*!40103 SET TIME_ZONE='+00:00' */;
13+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17+
18+
--
19+
-- Table structure for table `users`
20+
--
21+
22+
DROP TABLE IF EXISTS `users`;
23+
/*!40101 SET @saved_cs_client = @@character_set_client */;
24+
/*!40101 SET character_set_client = utf8 */;
25+
CREATE TABLE `users` (
26+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
27+
`name` varchar(70) NOT NULL,
28+
`email` varchar(70) NOT NULL,
29+
PRIMARY KEY (`id`)
30+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
31+
/*!40101 SET character_set_client = @saved_cs_client */;
32+
33+
--
34+
-- Dumping data for table `users`
35+
--
36+
37+
LOCK TABLES `users` WRITE;
38+
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
39+
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
40+
UNLOCK TABLES;
41+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
42+
43+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
44+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
45+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
46+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
47+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
48+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
49+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
50+
51+
-- Dump completed on 2014-08-26 14:20:40

0 commit comments

Comments
 (0)