We use the view helper in our main site template to create the link in the main menu bar using the code:
loggedInUser(); ?>
The final result looks like Figure 6.3 and provides an easily discoverable log out link.
Figure 6.3. The logged in welcome message.
The final part of authentication is now upon us and we can implement the ability to log out.
6.3.4 Logging out
In comparison to logging in, logging out is very simple as all we need to do is call Zend_Auth??™s clearIdenity
function. Listing 6.7 shows the log out action in the Auth controller.
Listing 6.7: The auth/logout Controller Action
public function logoutAction()
{
$auth = Zend_Auth::getInstance();
$auth->clearIdentity(); #1
$this->_redirect('/'); #2
}
(annotation) <#1. Unset the session variable.>
(annotation) <#2. Redirect to home page.>
As you can see, logging out really is simple, so it??™s time to move on to look at authorisation and giving
logged in users more rights than visitors. This is handled by Zend_Auth??™s sibling, Zend_Acl.
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
6.4 Implementing Authorisation
As we discussed in section 6.
Pages:
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199