PHP and Zend Framework

The Zend framework's controller,Zend_controller is designed to support websites with clean urls.To achieve this, all requests need

to go through a single index.php file known as the bootstrapper. This provides us with a central point for all pages of the application

and ensures that the environment is set up correctly for running the application. The Zend Framework is designed such that its files

must be on the include path. We also place our models directory on the include path so that we can easily load our model classed

later. To kick off we have to include the files Zend.php to gives us access to the Zend class which has the required static functions to

enable us to load any other Zend Framework class. The front controller uses a router class to map the requested url to the correct

php function to be used for displaying the page. In order for the router to operate, it needs to work out wich part of the url is the path

to our index.php so that ir can look at the url elements after that points. The Zend Framework's controller reserves a special action

called index as a default action. Remember that the model is the part that deals with the application's core purpose and hence deals

with the database. We will make use of the Zend Framework class Zend_ Db_Table which is used to find,insert,update and delete

rows from a database table. To use Zend_Db_Table,we need to tell it which databse to use along with a username and password.

The Zend Framework provides Zend_config to provide flexible object oriented access to configuration files. At the moment, the

configuration file can be a php array ,an ini file or an xml file. Zend_Db_Table is an abstract class .

Filters and Validators can be added to these elements that we have created. There are various ways of adding validators. The view

can be thought of as a templating system. Like a templating system, it allows you to keep all of your display logic separate from your

business logic. In Zend Framework, the view is represented by Zend_View. In most cases, the view is instantiated automatically by

the controller and we access it with $this->view. The view script is what actually contains the display logic necessary to output the

data prepared by your controller action and or your model. The first thing that the view will do upon render() is find the proper script.

The view looks at the controller name,the action name and mergers that with the location of the scripts to create a uri for the view

script. Zend Framework uses the Zend_Db class to connect to a database. Zend-Db and its related classes give you a PDO-like

interface to talk to your database. you have your adapter and you need to fetch some data. Plugins are for when you want to do

something on every request,regardless of the controller,without any interaction with the controller. Plugins require only that you

register the plugin with the front controller.Then the code it encapsulates will be executed. All the code in Plugins in encapsulated in

either the preDispatch() method or the postDispatch() method. Helpers are for when you want shared functionality that you want to

use selectively within controllers and for which you need some introspection or coupling with the controller. Helpers also allow you to

insert functionality before or after any action. As with plugins,helpers have preDispatch() and postDispatch() methods that if exist will

be called automatically. However,helpers also have a direct() method. direct() is called if you make a call directly to the helper.

As with everything in the Zend Framework,action helpers have a default place on the file system. There are several different levels of

model implementation that can be found in applications. The process of verifying logged in status or not is called authentication or

auth.Determing whether a user has specific rights and acting upon those rights is called access control.  Zend_Auth can be a

complicated beast as it allows you to define your own authentication methods using custom adapters. Natively,Zend Framework

comes with three adapters that you can use

,Zend_Auth_Adapter_Dbtable,Zend_Auth_Adapter_Digest,Zend_Auth_Adapter_Http.By extending the

Zend_Auth_Adapter_Interface you can build  your own custom adapters to authenticate against any backend service you choose.

While different adapters may have vastly different options and parameters,they all have one thing in common.,they all return a

Zend_Auth_Result when authenticate() is called.  The nice thing about Zend_Layout is that is accomplishes this task. Zend_Layout is

broken up into the main layout controller as well as a lot of little helpers.

你可能感兴趣的:(PHP,Access,UP,Go,Zend)