Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
CHAPTER 17 ■ THE ZEND FRAMEWORK APPLIED^267

//Overwrite the controller and action that the dispatch will use
$request->setControllerName('index');
$request->setActionName('login');
}
// else { access is ok, dispatch normally }
}
}
}

The next step is to integrate the authorization example from the previous chapter. To do this,
add a role column to the database users table and set the value for your role column to 'member'.
Then locate this line in your loginAction in your IndexController.php file (Listing 16-10):

$this->getHelper('redirector')->goto('index','index');

and change it to this:

//Try to forward the user back where they were trying to get to
$session = new Zend_Session_Namespace('ACLSecurity');
if(isset($session->originalRequestUri)) {
$this->getHelper('redirector')
->gotoUrl($session->originalRequestUri);
} else {
$this->getHelper('redirector')->goto('index','index');
}

This will make it so that when redirected users successfully log in, they will be taken to the
original URL they were trying to access.
Finally, register the plug-in with the front controller:

$front->registerPlugin(new YourPrefix_Controller_Plugin_Security($acl));

Now try to visit your /articles controller. You should be forwarded to /index/login. Once
successfully logged in, you will be sent back to /articles. You now have a basic ACL and
authentication integrated plug-in solution.

Using a Two-Step View


Zend_Layout serves to fulfill the common requirement of creating sites where each page has a
similar look and feel, often known as a site-wide template, two-step view, or a layout.
The concept of a layout is to avoid having to use prepended and postpended templates.
Instead, you use Zend_View_Helper_Placeholder to specify where content created by the controller-
action dispatch should be placed in the final output. This allows you to use a layout file that
represents the structure of the final page, including both <html> and </html> in the same file.

Creating a Master Layout.


In order to use the Zend_Layout component, you need to add the code shown in Listing 17-11
to your bootstrap file.

McArthur_819-9.book Page 267 Friday, February 29, 2008 8:03 AM

Free download pdf