Skip to content

Commit 3869174

Browse files
emiliodegniden
authored andcommitted
Modified SignupController to pass vars into view
Added users list Added some styles
1 parent 3309aeb commit 3869174

7 files changed

Lines changed: 66 additions & 13 deletions

File tree

app/controllers/IndexController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
class IndexController extends Controller
66
{
7-
7+
/**
8+
* Welcome and user list
9+
*/
810
public function indexAction()
911
{
12+
$this->view->users = Users::find();
1013
}
1114
}

app/controllers/SignupController.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44

55
class SignupController extends Controller
66
{
7-
7+
/**
8+
* Show form to register a new user
9+
*/
810
public function indexAction()
911
{
1012
}
1113

14+
/**
15+
* Register new user and show message
16+
*/
1217
public function registerAction()
1318
{
14-
1519
$user = new Users();
1620

1721
// Store and check for errors
@@ -20,15 +24,16 @@ public function registerAction()
2024
['name', 'email']
2125
);
2226

27+
// passing the result to the view
28+
$this->view->success = $success;
29+
2330
if ($success) {
24-
echo "Thanks for registering!";
31+
$message = "Thanks for registering!";
2532
} else {
26-
echo "Sorry, the following problems were generated: ";
27-
foreach ($user->getMessages() as $message) {
28-
echo $message->getMessage(), "<br/>";
29-
}
33+
$message = "Sorry, the following problems were generated:<br>" . implode('<br>', $user->getMessages());
3034
}
3135

32-
$this->view->disable();
36+
// passing a message to the view
37+
$this->view->message = $message;
3338
}
3439
}

app/views/index.phtml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Phalcon Tutorial</title>
6+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
7+
</head>
8+
<body>
9+
<div class="container">
10+
<?php echo $this->getContent(); ?>
11+
</div>
12+
</body>
13+
</html>

app/views/index/index.phtml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,32 @@
22

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

5-
echo $this->tag->linkTo("signup", "Sign Up Here!");
5+
echo $this->tag->linkTo(["signup", "Sign Up Here!", 'class' => 'btn btn-primary']);
6+
7+
if ($users->count() > 0) {
8+
?>
9+
<table class="table table-bordered table-hover">
10+
<thead class="thead-light">
11+
<tr>
12+
<th>#</th>
13+
<th>Name</th>
14+
<th>Email</th>
15+
</tr>
16+
</thead>
17+
<tfoot>
18+
<tr>
19+
<td colspan="3">Users quantity: <?php echo $users->count(); ?></td>
20+
</tr>
21+
</tfoot>
22+
<tbody>
23+
<?php foreach ($users as $user) { ?>
24+
<tr>
25+
<td><?php echo $user->id; ?></td>
26+
<td><?php echo $user->name; ?></td>
27+
<td><?php echo $user->email; ?></td>
28+
</tr>
29+
<?php } ?>
30+
</tbody>
31+
</table>
32+
<?php
33+
}

app/views/signup/index.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</p>
1414

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

1919
<?php echo $this->tag->endForm() ?>

app/views/signup/register.phtml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="alert alert-<?php echo $success === true ? 'success' : 'danger'; ?>">
2+
<?php echo $message; ?>
3+
</div>
4+
5+
<?php echo $this->tag->linkTo(['/', 'Go back', 'class' => 'btn btn-primary']); ?>

public/index.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
APP_PATH . '/controllers/',
1818
APP_PATH . '/models/',
1919
]
20-
)->register()
21-
;
20+
)->register();
2221

2322
// Create a DI
2423
$di = new FactoryDefault();

0 commit comments

Comments
 (0)