Skip to content

Commit

Permalink
Modified SignupController to pass vars into view
Browse files Browse the repository at this point in the history
Added users list
Added some styles
  • Loading branch information
emiliodeg authored and niden committed Nov 22, 2018
1 parent 3309aeb commit 3869174
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
5 changes: 4 additions & 1 deletion app/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

class IndexController extends Controller
{

/**
* Welcome and user list
*/
public function indexAction()
{
$this->view->users = Users::find();
}
}
21 changes: 13 additions & 8 deletions app/controllers/SignupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

class SignupController extends Controller
{

/**
* Show form to register a new user
*/
public function indexAction()
{
}

/**
* Register new user and show message
*/
public function registerAction()
{

$user = new Users();

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

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

if ($success) {
echo "Thanks for registering!";
$message = "Thanks for registering!";
} else {
echo "Sorry, the following problems were generated: ";
foreach ($user->getMessages() as $message) {
echo $message->getMessage(), "<br/>";
}
$message = "Sorry, the following problems were generated:<br>" . implode('<br>', $user->getMessages());
}

$this->view->disable();
// passing a message to the view
$this->view->message = $message;
}
}
13 changes: 13 additions & 0 deletions app/views/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Phalcon Tutorial</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<?php echo $this->getContent(); ?>
</div>
</body>
</html>
30 changes: 29 additions & 1 deletion app/views/index/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,32 @@

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

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

if ($users->count() > 0) {
?>
<table class="table table-bordered table-hover">
<thead class="thead-light">
<tr>
<th>#</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3">Users quantity: <?php echo $users->count(); ?></td>
</tr>
</tfoot>
<tbody>
<?php foreach ($users as $user) { ?>
<tr>
<td><?php echo $user->id; ?></td>
<td><?php echo $user->name; ?></td>
<td><?php echo $user->email; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
}
2 changes: 1 addition & 1 deletion app/views/signup/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</p>

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

<?php echo $this->tag->endForm() ?>
5 changes: 5 additions & 0 deletions app/views/signup/register.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="alert alert-<?php echo $success === true ? 'success' : 'danger'; ?>">
<?php echo $message; ?>
</div>

<?php echo $this->tag->linkTo(['/', 'Go back', 'class' => 'btn btn-primary']); ?>
3 changes: 1 addition & 2 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
APP_PATH . '/controllers/',
APP_PATH . '/models/',
]
)->register()
;
)->register();

// Create a DI
$di = new FactoryDefault();
Expand Down

0 comments on commit 3869174

Please sign in to comment.