Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
CHAPTER 16 ■ ADVANCED ZEND FRAMEWORK^247

/*

The next line stores the entire database row in the users
Zend_Auth identity. Normally only the 'identity' column—
in this case, the e-mail—is stored as a string. By
storing the entire record, you can access the user's
name and ID too.
*/
$auth->getStorage()->write($adapter->getResultRowObject());

//Redirect to /index/index when successfully logged in
$this->getHelper('redirector')->goto('index','index');
} else {
//In this case, the authentication failed.
$this->getHelper('FlashMessenger')
->addMessage(
"The login credentials provided are not valid."
);
$this->getHelper('redirector')->goto('login');
}
} else {
foreach($zfi->getMessages() as $field=>$messages) {
foreach($messages as $message) {
$this->getHelper('FlashMessenger')
->addMessage($field. ' : '. $message);
}
}
$this->getHelper('redirector')->goto('login');
}
}
$this->view->messages = $this->getHelper('FlashMessenger')
->getMessages();
}

You will also need a login.phtml view in /views/scripts/index/, as shown in Listing 16-
11.

Listing 16-11. The Login View (login.phtml)

<?php foreach($this->messages as $message) { ?>
<p>
<strong>ERROR: </span><?php echo $this->escape($message); ?></strong>
</p>
<?php } ?>

<form method="post">
<p>Email Address:<br />
<input type="text" name="email"/>
</p>

McArthur_819-9C16.fm Page 247 Friday, February 29, 2008 5:07 PM

Free download pdf