Use the symfony command to create a project _ php instance

Source: Internet
Author: User
This article mainly introduces how to use the symfony command to create a project, and analyzes the usage of the Symfony command and the related skills of Project Creation in the form of instances, for more information about how to use the symfony command to create a project, see the example in this article. 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.