ZendFramework learning diary (2) -- HelloWorld this article mainly demonstrates how to use zf command line tool to build a project based on the ZendFramework framework. It is also a small exercise for ZendFramework beginners. (1) create a project (in Windows) Open CMD and switch the directory to the directory where the project to be created is located.
Zend Framework learning diary (2) -- HelloWorld this article mainly demonstrates how to use the zf command line tool to create a project based on the Zend Framework. It is also a small exercise for me to learn about Zend Framework. (1) create a project (in Windows) Open CMD and switch the directory to the directory where the project to be created is located.
Zend Framework learning diary (2) -- HelloWorld
This article mainly demonstrates how to use the zf command line tool to build a project based on the Zend Framework. It is also a small exercise for me to learn about Zend Framework.
(1) create a project (in Windows)
Open CMD, switch the directory to the directory where the new project is to be created, and enter "zf create project HelloWorld", as shown below:
D:/workphp/www> zf create project HelloWorldCreating project at D:/workphp/www/HelloWorldNote: This command created a web project, for more information setting up your VHOST, please see docs/READMETesting Note: PHPUnit was not found in your include_path, therefore no testing actions will be created.
Zf automatically creates some directories and files. The directory structure is as follows:
About the directory structure of the HelloWorld project:
1. The application directory is where the source code is stored. Because the Zend framework adopts the MVC mode, the controllers, models, and views sub-directories are available, while the congfigs sub-directories are placed in the configuration file.
2. place documents in the docs directory; place Zend Framework in the library directory (the directory is empty because Zend Framework is placed elsewhere and include_path is added); The public directory is important, it is the directory released by the site. All files under this directory can be accessed through a browser; the tests directory is the unit test directory.
3. zfproject. xml is a record file of the zf tool. Some zf commands will update this file.
NOTE: For the Zend Framework MVC mode, refer to the http://framework.zend.com/manual/en/learning.quickstart.intro.html
(2) test Zend Framework
Make sure that the Apache server is enabled and enter "http: // localhost: 8088/HelloWorld/public/" in the browser. I modified the default port of Apache (how to modify it, as mentioned in another article, here ). The following interface should appear, indicating that Zend Framework is working properly. gx! (If not, refer to "Zend Framework learning diary (1) -- Environment setup ")
Note: For url rules, http: // domain name (IP)/public/controller/action. A controller can have multiple actions, and action is used to process the view, the controller controls these actions. By default, IndexController and indexAction are available (see IndexController under the controllers directory. php), so the complete url path here should be http: // localhost: 8088/HelloWorld/public/index. For more information, see Zend Framework manual.
(3) Two Step View Design Mode
Make sure that CMD is in the HelloWorld directory and enter "zf enable layout", as shown below:
D:/workphp/www/HelloWorld> zf enable layoutLayouts have been enabled, and a default layout created at D:/workphp/www/HelloWorld/application/layouts/scripts/layout. phtmlA layout entry has been added to the application config file.
You will find that the application directory has an additional layouts directory, as well as the subdirectories scripts and the file layout. phtml. If you look closely, you will find the code on the "Welcome to the Zend Framework" interface, In the scripts-> index. phtml in the views directory, as shown below:
After Zend Studio is installed, you can open it directly or use notepad or wordpad. Delete all content in index. phtml and add the following code:
<P id = "welcome"> Hello World! </P>
Then open the automatically generated layout. phtml (HelloWorld-> application-> layouts-> scripts) and find that there is only one line of code in the content, as shown below:
<? Php echo $ this-> layout ()-> content;?>
On this basis, I added some code to complete it into a simple html file, as shown below:
<Html> <pead> <title> HelloWorld! </Title> <meta http-equiv = "Content-Type" content = "text/html; charset = gbk"/> <mce: style type = "text/css"> <! -- # Welcome {color: red;} --> </mce: style> <style type = "text/css" mce_bogus = "1" >#welcome {color: red ;} </style> </pead> <body> <? Php echo $ this-> layout ()-> content;?> </Body> </ptml>
Obviously, we can see that index. phtml is the echo output content here. I just added some html and headTwo Step design patterns. There are two views, layout. phtml is the overall layout, index. phtml is the specific content (which I personally understand ). Remember to save the above changes and refresh the browser again. The effect is as follows:
As you can see, the title is "HelloWorld" and the text "HelloWorld" also turns red. This article ends.
The Code has been uploaded to http://download.csdn.net/source/3200862 for download. Welcome!