Getting started with ZendFramework

Source: Internet
Author: User
: This article mainly introduces ZendFramework. For more information about PHP tutorials, see. 1. Create YourProject

For details, see this article:

Http://blog.csdn.net/u012675743/article/details/45511019

II. The BootStrap

Bootstrap is used to define the initialization of your project resources and components. Class:

//application/Bootstrap.php class Bootstrapextends Zend_Application_Bootstrap_Bootstrap{}

For details, refer to this article:

Http://blog.csdn.net/u012675743/article/details/45510903


III. Configuration

You often need to configure the application by yourself. the default configuration file isapplication/configs/application.ini,

The command is also included to set the PHP environment and declare the bootstrap path,

; application/configs/application.ini[production]phpSettings.display_startup_errors = 0phpSettings.display_errors = 0includePaths.library = APPLICATION_PATH "/../library"bootstrap.path = APPLICATION_PATH "/Bootstrap.php"bootstrap.class = "Bootstrap"resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"[staging : production][testing : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1[development : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1

IV. Action Controllers

A controller should have one or more methods, which can be requested through a browser. You can usually write an indexcontroller as the site's homepage.
The default indexcontroller is as follows:

// application/controllers/IndexController.phpclass IndexController extends Zend_Controller_Action{    public function init()    {        /* Initialize action controller here */    }    public function indexAction()    {        // action body    }}

5. Views

Each controller has a corresponding view under application/views/scripts. And the corresponding name is 'Controller/controller. phtml'. it mainly writes the page to be displayed on the front-end.


6. Create A Layout

Enter:


Remember to switch to the project folder, or the following prompt will appear:


Open the layouts folder and a scripts folder will appear.

VII. Create a Model andDatabase Table

You must write a table class for each table to be operated on in the database. $ _ primary is the primary key of the table. for example:

 

8. Create A Form

It is very convenient to use the form of the framework to submit data. Create the directory forms under application, that is, application/forms, and create the corresponding form class.

For example:

  setMethod('post');        // Add an email element       $this->addElement('text', 'email', array(           'label'      => 'Your emailaddress:',           'required'   => true,           'filters'    =>array('StringTrim'),           'validators' => array(                'EmailAddress',           )       ));        // Add the comment element       $this->addElement('textarea', 'comment', array(           'label'      => 'PleaseComment:',           'required'   => true,           'validators' => array(                array('validator' =>'StringLength', 'options' => array(0, 20))                )       ));        // Add a captcha       $this->addElement('captcha', 'captcha', array(           'label'      => 'Please enterthe 5 letters displayed below:',           'required'   => true,           'captcha'    => array(                'captcha' => 'Figlet',               'wordLen' => 5,                'timeout' => 300           )       ));       // Add the submit button       $this->addElement('submit', 'submit', array(           'ignore'   => true,           'label'    => 'Sign Guestbook',       ));        // And finally add some CSRF protection       $this->addElement('hash', 'csrf', array(           'ignore' => true,       ));    }} 


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the Zend Framework entry, including some content, and hopes to help those who are interested in the PHP Tutorial.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.