1. Create YourProject
Please read this article for details:
http://blog.csdn.net/u012675743/article/details/45511019
2. The BootStrap
Bootstrap is used to define your project resources and component initialization. The categories are as follows:
//application/Bootstrap.php class Bootstrapextends Zend_Application_Bootstrap_Bootstrap { }
For details, you can also refer to this article:
http://blog.csdn.net/u012675743/article/details/45510903
Three. Configuration
You often need to configure the application yourself. The default configuration file is in <em>application/configs/application.ini</em>
,
which also contains instructions to set up the PHP environment and declare the bootstrap path,
; application/configs/application.ini [production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.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 = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1
Four. Action Controllers
A controller should have one or more methods, which can be requested through the browser. Usually you can write an indexcontroller as the home page of the site.
The default indexcontroller is as follows:
// application/controllers/IndexController.php class 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 name it accordingly ‘controller/controller.phtml’, mainly writing the page to be displayed at the front desk.
Six. Create A Layout
Enter at the command line:
Remember to switch to the project folder, otherwise the following prompt will appear:
Then open the layouts folder and a scripts folder will appear.
You need to write a table class for each table to be operated in the database. $_primary is the primary key of the table, for example:
<?php class Book extends Zend_Db_Table{ protected $_name = 'book'; protected $_primary = 'id'; }
8. Create A Form
It is very convenient to use the framework's form to submit data. Create the directory forms under application, namely application/forms, and create the corresponding form class.
For example:
<?php class Application_Form_Guestbook extendsZend_Form { public function init() { // Set the method for the display form to POST $this->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 Statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.
The above has introduced the introduction to Zend Framework, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.