Use the symfony command to create a project. use the symfony command to create a project _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Run the symfony command to create a project. run the symfony command to create a project. Run the symfony command to create a project. run the symfony command to create a project. This document describes how to use the symfony command to create a project. For your reference, refer to the method for creating a project using the symfony command and the symfony command for creating a project.

This example describes how to create a project using the symfony command. We will share this with you for your reference. The details are as follows:

Overview

This section describes the rational structure framework of a Symfony project and uses the symfony command to initialize the project structure.

Introduction

In symfony, a project is a group of services and valid operations under a specified domain name, sharing the same project model.

In a project, operations in an application are a set of logic. each application can run independently and does not interfere with other applications in the same project.

In most cases, a project contains two applications, one for front-end display, the other for backend processing, and the same database. Of course, you can also include many small sites in a project. each site is a different application. Note that the absolute path must be used for hyperlinks used between different applications.

Each application is a group of modules, and each module is responsible for a special function. A module usually uses a page or a group of pages for similar functions. For example, the module can be home, articles, help, shoppingCart, account, and so on.

Module Functions: Each module has its own functions. for example, the shoppingCart (shopping cart) module must have the add, show, and update functions. Function behavior can be seen as page behavior in a typical web application.

If a new project has too many levels, you can easily group all the functions in the module, so that the file structure can be kept simple. When the application is more complex, functions can be organized in the logic module.

Each application can run in different environments, such as different configurations or databases. Generally, each new application runs in three environments (development, testing, and final products. If needed, each application can run in more environments. in different environments, you only need to modify the configuration accessories.

For example, you need to record warnings and errors in a test environment, while in a final product environment, you only need to record errors. Cache Acceleration is usually not enabled in the development environment, but must be enabled in the testing and final product environments. Data used for testing may be stored in the remote database of the final product in the development environment and test environment. All environments can coexist on one machine, while the product server usually only has the final product environment.

Note: If you use symfony through sandbox, you do not need to set the project or application, sandbox) an internal project named 'SF _ sandbox' and an application named 'frontend' have been prepared. You do not need to set up a web server. you only need to place your program in the web/root directory.

Pake

SymFony uses a dedicated tool Pake to manage projects, applications, and modules. Pake is a php tool, similar to the Rake command (this is a tool that converts the make command to Ruby ). It automates some management tasks based on a special configuration file named pakefile. php. If you use the pake tool instead of the symfony command line, all operations will become very simple.

To get a list of all valid management operation commands, simply enter the following in your project directory:

$ symfony -T

The CLI (command line operation) task scheduling is used for the preliminary phase of a project. For a complete description of CLI task scheduling, see the CLI chapter.

Project settings

Before everything starts, you must create a new directory to store the project:

$ mkdir /home/steve/myproject

Then, initialize the project to generate the original file and directory, and enter the following simple:

$ cd /home/steve/myproject$ symfony init-project myproject

This is an overview of the newly created file system tree structure:

Apps/
Batch/
Cache/
Config/
Data/
Doc/
Lib/
Log/
Test/
Web/

The symfony command can be called at any time in the available directory of the current project.

Application Settings

The project has not been completed yet. it requires at least one application. First, use the symfony init-app command to initialize an application. use the parameters following the command to name the application name:

$ symfony init-app myapp

In this way, a myapp directory is created in the apps/folder under the root directory of the project, which contains a default application configuration for your site and a set of directory files:

Apps/
Myapp/
Config/
I18n/
Lib/
Modules/
Templates/

Some PHP files that act as front-end controllers in their default environments are also created in the web Directory of the project Root Directory:

Web/
Index. php
Myapp_dev.php

Index. php is the front-end controller of the new production application. Because when you create the first application in this project, Symfony creates a Call index. php files, such as myapp. php (if you add a new application named mynewapp, the front-end controller of the new product will be named mynewapp. php ). Call the front-end controller myapp_dev.php when running a program in the development environment.

Note: If you have carefully read the introduction, you may be surprised by the location of the myapp_test.php file. In fact, the test environment is used to perform unit tests on the components of your application. it does not require a front-end controller. For more details, see unit test.

From now on, the/home/steve/myproject/directory will serve as the root directory of the project. The path of the root directory has been saved as the constant SF_ROOT_DIR, which is defined in index. php file, and we will use this constant name to replace the actual path to avoid confusing readers who are not called Steve: because the author puts the project in the/home/steve/myprojetc Directory, this path may vary with everyone, so the constant SF_ROOT_DIR is used to replace the actual path ).

Web server settings

To access and test new applications, you need to configure the web server. Here is an Apache example. add a new virtual host to the httpd. conf configuration file:

 
   AllowOverride All Allow from All
 
 
   ServerName myapp.example.com DocumentRoot "/home/steve/myproject/web" DirectoryIndex index.php Alias /sf /$data_dir/symfony/web/sf 
  
     AllowOverride All  Allow from All 
  
 

Note: The $ data_dir variable in the preceding configuration must be replaced with your PEAR Library Directory. For example, in * nix, you can enter:

 Alias /sf /usr/local/lib/php/data/symfony/web/sf

You can find

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.