Zend Framework Introduction Environment configuration and the first Hello World example (with demo source download) _php instance

Source: Internet
Author: User
Tags php source code
This example describes the environment configuration of the Zend Framework and the first Hello World program. Share to everyone for your reference, as follows:

The first step: Confirm your PHP Environment:

1. Please phper confirm that your PHP version is at 5.2.0 or above. If not, then. Please update to 5.2.0, otherwise. The Zend Framework doesn't seem to work. I've tried it myself.

Have encountered such a problem. So please test yourselves. PHP source code The latest version of the download address is: http://www.php.net/downloads.php.

2. After your PHP environment is configured, open the php.ini file to verify that the PDO extension is turned on. If not, please remove the extension=php_pdo.dll before.

3. Open the httpd.conf file inside the Apache folder. Find the Apache mod_rewrite module, confirm LoadModule Rewrite_module Modules/mod_ Rewrite.so is open. If not, remove the # number in front of it.

4. Find the httpd.conf file, if allowoverride is none: Please make sure none is changed to all. So you write. htaccess such a file will play a role.

5. Restart your Apache server: In this way our PHP environment can be used Zend Framewrok.

Step two: Get the Zend Framework source code:

1. Download the latest version of the Zend Framework source. Now the latest version seems to be 1.7.0. But afraid of instability. So please phper themselves decide what version to use.

You can download http://www.zendframework.com/download/latest the latest version of the source code here.

Step three: Create a project directory:

I don't want to say anything more. I'll show you the picture. Is my project directory for this tutorial ... I have a description on the above. You can create a directory as follows: Of course, below I will provide source download.

But it is recommended that friends do it by themselves. Before you can learn more. I give also source code also just for everybody to do as a reference.

Fourth Step: Program Description:

I don't say much here. Because there are annotations in every file. I don't think it's too hard. If some friends don't understand please leave a message on the blog. I will pay attention to this blog. Try to answer your questions. Thank you..

index.php (website entrance) documents and instructions:

<?phperror_reporting (e_all| e_strict);d ate_default_timezone_set (' Asia/shanghai '); Set_include_path ('. '). Path_separator. '. /library '. Path_separator. '. /application/models/'. Path_separator. Get_include_path ()); Require_once ' zend/loader.php '; Zend_loader::registerautoload ();//Set Zend Framework automatically load class file $registry = Zend_registry::getinstance ();//Set Template display path $view = new Zend_view (); $view->setscriptpath ('./application/views/scripts/'); $registry [' View '] = $view;//Register view// Set the controller $frontcontroller =zend_controller_front::getinstance (); $frontController->setbaseurl ('/zendframework ')// Set basic path->setparam (' Noviewrenderer ', True)->setcontrollerdirectory ('./application/controllers ') Throwexceptions (True)->dispatch ();

indexcontroller.php File and Description:

<?phpclass Indexcontroller extends Zend_controller_action {function init () {$this->registry = Zend_registry:: GetInstance (); $this->view = $this->registry[' view '; $this->view->baseurl = $this->_request-> Getbaseurl ();} function Indexaction () {//Here assign a value to the variable, display $this->view->bodytitle = ' in the index.phtml template

Hello world!

'; Echo $this->view->render (' index.phtml ');//Display template}}

index.phtml Template File Description:

<?= $this->bodytitle;?>
 
  

Full instance code click here to download this site.

But I didn't add zend to my library. Please phper yourself to add. If there's any problem. Ask a friend to leave a message for me.

More interested in Zend related content readers can view the topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "

It is hoped that this article will help you to design PHP based on the Zend Framework framework.

  • 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.