Management actions
There are a couple of final management tasks that users can do to view or update their accounts and log out.
When a user updates an account, you can see from Listing 10 that the
username is retrieved from the SESSION
array, so this should not be changeable. To make it unchangeable in
the register view, define it as shown in Listing 24.
Listing 24. Modifying register.php
...
<p>Username:
<?php
if($this->button == 'Update')
echo $this->username .
'<input name=\
"username" type="hidden" value="'.
$this->username . '">';
else
echo '<input name="username" value="'.
$this->username . '">';
?>
...
|
Thus, if the user is updating his account, the username is shown, the input tag is hidden, and its value is set to the logged-in user's username. Otherwise, an empty text box is shown. The modifications can be seen in Figure 8.
Figure 8. Viewing the register view in update/view profile mode
Another great example using the same view for two purposes with the Zend Framework.
Logging out destroys the current session. Define the logoutAction method in the UserController, as shown in Listing 25.
Listing 25. Logging out
public function logoutAction()
{
session_destroy();
$this->_redirect('/');
}
|
This destroys the current session and sends the user back to the root. Congratulations! You're all done.




