Table of Contents
How to use the symfony command to create a project, the symfony command to create a project
您可能感兴趣的文章:
Home Backend Development PHP Tutorial How to use the symfony command to create a project, the symfony command to create a project_PHP tutorial

How to use the symfony command to create a project, the symfony command to create a project_PHP tutorial

Jul 12, 2016 am 08:56 AM
symfony Create project Order

How to use the symfony command to create a project, the symfony command to create a project

The example in this article describes how to use the symfony command to create a project. Share it with everyone for your reference, the details are as follows:

Overview

This chapter describes the reasonable structural framework of a Symfony project, and uses the symfony command to initialize the project structure.

Introduction

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

In a project, the operations in the application are a set of logic; each application can run normally and independently without interfering with other applications in the same project.

In most cases, a project will contain two applications, one responsible for foreground display and one responsible for background processing, using the same database. Of course, you can also include many small sites in one project, each site being a different application. Note that hyperlinks used between different applications must use absolute paths.

Each application is a set of modules, each module is responsible for a special function. A module usually uses a page or a group of pages for similar functionality. For example, modules can be home, articles, help, shoppingCart, account, etc.

Module functions: Each module has their own functions, for example, the shoppingCart (shopping cart) module must have add (add), display (show) and update (update) functions. Functional behavior can be thought of as page behavior in a typical web application.

If a new project has too many levels, it is easy to group all the functions in the module so that the file structure can be kept simple. When the application becomes more complex, functions can be organized in logical modules.

Each application can run in different environments, for example, different configurations or databases. Generally every new application will run in three environments (development, testing and final production). Each application can run in more environments if necessary, and only needs to modify the configuration accessories in different environments.

For example, a test environment will need to log warnings and errors, while a final production environment will only need to log errors. Cache acceleration is usually not turned on in development environments, but needs to be turned on in testing and final production environments. Development and test environments may require test data to be stored in the final product's remote database. All environments can coexist on a single machine, and typically only the final production environment is on the production server.

Note: If you are using symfony through the sandbox, you do not need to set up a project or application. A project named 'sf_sandbox' and a project named ' frontend' application. You don't need to set up a web server either, just place your program in the web/ root directory.

Pake

SymFony uses the specialized tool Pake to manage projects, applications and modules. Pake is a php tool similar to the Rake command (it's a tool that converts the make command to Ruby). It automates some administrative tasks based on a special configuration file called pakefile.php. If you use the pake tool instead of the symfony command line, everything becomes very simple.

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

1

$ symfony -T

Copy after login

CLI (command line operation) task scheduling is used during the early stages of a project. A complete description of CLI task scheduling is available in the CLI chapter.

Project Settings

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

1

$ mkdir /home/steve/myproject

Copy after login

Then, start initializing the project to generate original files and directories, simply enter:

1

2

$ cd /home/steve/myproject

$ symfony init-project myproject

Copy after login

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 directory available in the current project.

App Settings

The project is not finished yet, it still needs at least one application. First use the symfony init-app command to initialize an application, and use the parameters following the command to name the application:

1

$ symfony init-app myapp

Copy after login

This creates a myapp directory in the apps/ folder in the root directory of the project, which contains a default application configuration and a set of directory files for your site:

apps/
myapp/
config/
i18n/
lib/
modules/
Templates/

Some php files that act as front-end controllers in their respective default environments are also created in the web directory of the project root directory:

web/
index.php
myapp_dev.php

index.php是production新应用程序的前端控制器。因为你创建这个项目中的第一个应用程序时,Symfony创建了一个调用 index.php的文件,例如 myapp.php (如果你现在添加一个名为 mynewapp 的新应用程序,新产品的前端控制器将被命名为mynewapp.php)。在 开发环境中运行程序时,调用前端控制器 myapp_dev.php。

注意:你如果仔细阅读了介绍,你可能会对myapp_test.php文件的位置感到意外。事实上,测试 环境是用于对你的应用程序的构件进行单元测试,它不需要前端控制器。可以参考单元测试章节去了解更多详细内容。

从现在开始,/home/steve/myproject/ 目录将会作为项目的根目录。根目录的路径已经被保存为 SF_ROOT_DIR 常量,定义在 index.php 文件中,并且我们将会用这个常量名代替实际路径以避免把不叫Steve的读者搞糊涂了(译者注:因为作者将项目放在/home/steve /myprojetc的目录下,这个路径每个人可能都不尽相同,所以使用常量SF_ROOT_DIR来代替了实际路径)。

Web服务器设置

为了访问和测试新的应用程序,需要配置web服务器。这有一个Apache的例子,在 httpd.conf 配置文件中加入一个新的虚拟主机:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<Directory "/$data_dir/symfony/web/sf">

 AllowOverride All

 Allow from All

</Directory>

<VirtualHost *:80>

 ServerName myapp.example.com

 DocumentRoot "/home/steve/myproject/web"

 DirectoryIndex index.php

 Alias /sf /$data_dir/symfony/web/sf

 <Directory "/home/steve/myproject/web">

  AllowOverride All

  Allow from All

 </Directory>

</VirtualHost>

Copy after login

注意:上面的配置中的 $data_dir 变量需要替换成你的PEAR库目录。例如:在*nix系统中,你可以输入:

1

<code> Alias /sf /usr/local/lib/php/data/symfony/web/sf</code>

Copy after login

你可以在安装章节找到更多关于PEAR目录的信息。

重启Apache服务之后,就可以看到调用新创建的应用程序的页面,只需要在一个标准的web浏览器的地址栏输入下列路径:

http://myapp.example.com/index.php/

或者,在调试模式下使用这个路径:

http://myapp.example.com/myapp_dev.php/

注意:Symfony显示‘简短漂亮的(smart)'路径时用到了 mod_rewrite 模块。如果你的Apache版本没有将 mod_rewrite 模块编译进去,那么需要在 httpd.conf 中检查模块mod_rewrite是否是动态模块方式(DSO)安装的,并且确认是否已经打开(译者注:关于Apache的mod_rewrite模块安 装和使用方法请参考Apache相关文档,这里假设读者已经具备这方面知识而不作过多说明):

1

2

AddModule mod_rewrite.c

LoadModule rewrite_module modules/mod_rewrite.so

Copy after login

你可以在路由(routing)章节了解更多关于简短路径(smart urls)的信息。

Symfony 兼容其它服务器配置方式。你也可以,例如,用别名(alias)代替虚拟主机访问symfony应用程序。若需要了解更多关于web服务器配置信息,请查阅相关章节。

模块设置

你这个新的应用程序并不出众,它缺乏吸引人的功能。如果你想增加功能性,你需要在在其中用到模块。这里再一次用到了 symfony 命令,参数为 init-module ,后面跟着应用程序名称和新模块的名称:

1

$ symfony init-module myapp mymodule

Copy after login

创建以后的树结构如下:

modules/
mymodule/
actions/
config/
lib/
templates/
validate/

新模块直接可以被使用:

http://myapp.example.com/index.php/mymodule

然后你需要让它正常的工作,编辑文件 myapp/modules/mymodule/templates/indexSuccess.php 输入:

Hello, world !

保存它,刷新刚才的页面就可以看到内容!

源文件版本控制(Source versioning)

应用程序设置完成之后,建议开始进行源文件版本控制。Symfony从一开始就支持CVS(译者注:版本控制系统),建议使用Subversion(译者注:一个版本控制系统软件,采用CVS 的运作模型, 并以取代CVS 为目标)。下面的例子列出了一些Subversion的命令,用于从在一个安装了Subversion的服务器上创建一个新项目的"仓库"(译者注:repository,源代码储存的地方)。对于Windows用户,建议客户端使用TortoiseSVN。关于源文件版本控制的更多信息和命令用法,请参考Subversion文档。

下面的例子假设$SVNREP_DIR是一个已经定义的环境变量。如果你还没有定义它,你需要用"仓库"的实际路径代替$SVNREP_DIR变量。

现在让我们开始创建myproject项目的新"仓库":

1

$ svnadmin create $SVNREP_DIR/myproject

Copy after login

然后用下面这串命令创建新"仓库"的基本组织结构(规划),其中包含 trunk, tags 和 branches 三个目录:

[code]$ svn mkdir -m "layout creation" file:///$SVNREP_DIR/myproject/trunk file:///$SVNREP_DIR/myproject/tags file:///$SVNREP_DIR/myproject/branches[/code]

这将是你第一个版本。现在你必须导入项目的文件,但不包括缓存和日志等临时文件:

1

2

3

4

$ cd /home/steve/myproject

$ rm -rf cache/*

$ rm -rf log/*

$ svn import -m "initial import" . file:///$SVNREP_DIR/myproject/trunk

Copy after login

检查提交的文件:

1

$ svn ls file:///$SVNREP_DIR/myproject/trunk/

Copy after login

看上去很不错。现在SVN"仓库"已经记录了所有项目文件的版本(和更改历史)。就是说实际路径为 /home/steve/myproject 的目录中所有的文件都已经被"仓库"记录。要做到这一点,首先重命名 myproject 目录名,当一切运行正常的时候可以删除它,并且在新目录中向"仓库"提交一个checkout:

1

2

3

4

$ cd /home/steve

$ mv myproject myproject.origin

$ svn co file:///$SVNREP_DIR/myproject/trunk myproject

$ ls myproject

Copy after login

现在你可以在 /home/steve/myproject/ 目录下的文件中工作,并且提交修改到"仓库"中。不要忘记作一些清理和删除myproject.origin目录,它现在没有用了。

还有一些另外的设置。当你向"仓库"中提交工作目录时,会复制一些多余的文件,像项目中 cache 和 log 目录下的文件。因此你需要针对这个项目在svn中指定一个忽略列表。你也需要重新将 cache/ 和 log/ 目录的权限设置为完全控制,在访问时产生的文件SVN将不会储存:

1

2

3

4

$ cd /home/steve/myproject

$ svn propedit svn:ignore .

$ chmod 777 cache

$ chmod 777 log

Copy after login

这将调用在SVN中设置的默认的文本编辑器。如果没有生效,就像下面这样设置subversion首选的编辑器:

1

2

$ export SVN_EDITOR=<name of editor>

$ svn propedit svn:ignore .

Copy after login

直接在SVN中的忽略列表中加入myproject子目录,这样提交的时候就忽略了:

1

2

cache

log

Copy after login

保存然后退出,这样就完成了。

希望本文所述对大家基于Symfony框架的PHP程序设计有所帮助。

您可能感兴趣的文章:

  • Symfony2框架创建项目与模板设置实例详解
  • Symfony页面的基本创建实例详解
  • symfony2.4的twig中date用法分析
  • Symfony2之session与cookie用法小结
  • Symfony2实现从数据库获取数据的方法小结
  • Symfony2实现在controller中获取url的方法
  • Symfony2框架学习笔记之表单用法详解
  • Symfony2框架学习笔记之HTTP Cache用法详解
  • Symfony2学习笔记之插件格式分析
  • Symfony2学习笔记之系统路由详解
  • Symfony2学习笔记之控制器用法详解
  • Symfony2学习笔记之模板用法详解
  • Symfony2创建页面实例详解

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1111328.htmlTechArticle使用symfony命令创建项目的方法,symfony命令创建项目 本文实例讲述了使用symfony命令创建项目的方法。分享给大家供大家参考,具体如下:...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run SUDO commands in Windows 11/10 How to run SUDO commands in Windows 11/10 Mar 09, 2024 am 09:50 AM

The sudo command allows users to run commands in elevated privilege mode without switching to superuser mode. This article will introduce how to simulate functions similar to sudo commands in Windows systems. What is the Shudao Command? Sudo (short for "superuser do") is a command-line tool that allows users of Unix-based operating systems such as Linux and MacOS to execute commands with elevated privileges typically held by administrators. Running SUDO commands in Windows 11/10 However, with the launch of the latest Windows 11 Insider preview version, Windows users can now experience this feature. This new feature enables users to

How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 Feb 29, 2024 pm 04:34 PM

This article will introduce readers to how to use the command prompt (CommandPrompt) to find the physical address (MAC address) of the network adapter in Win11 system. A MAC address is a unique identifier for a network interface card (NIC), which plays an important role in network communications. Through the command prompt, users can easily obtain the MAC address information of all network adapters on the current computer, which is very helpful for network troubleshooting, configuring network settings and other tasks. Method 1: Use "Command Prompt" 1. Press the [Win+X] key combination, or [right-click] click the [Windows logo] on the taskbar, and in the menu item that opens, select [Run]; 2. Run the window , enter the [cmd] command, and then

Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Feb 29, 2024 pm 05:52 PM

In Win11 system, you can enable or disable Hyper-V enhanced session mode through commands. This article will introduce how to use commands to operate and help users better manage and control Hyper-V functions in the system. Hyper-V is a virtualization technology provided by Microsoft. It is built into Windows Server and Windows 10 and 11 (except Home Edition), allowing users to run virtual operating systems in Windows systems. Although virtual machines are isolated from the host operating system, they can still use the host's resources, such as sound cards and storage devices, through settings. One of the key settings is to enable Enhanced Session Mode. Enhanced session mode is Hyper

cmdtelnet command is not recognized as an internal or external command cmdtelnet command is not recognized as an internal or external command Jan 03, 2024 am 08:05 AM

The cmd window prompts that telnet is not an internal or external command. This problem must have deeply troubled you. This problem does not appear because there is anything wrong with the user's operation. Users do not need to worry too much. All it takes is a few small steps. Operation settings can solve the problem of cmd window prompting telnet is not an internal or external command. Let’s take a look at the solution to the cmd window prompting telnet is not an internal or external command brought by the editor today. The cmd window prompts that telnet is not an internal or external command. Solution: 1. Open the computer's control panel. 2. Find programs and functions. 3. Find Turn Windows features on or off on the left. 4. Find “telnet client

Super practical! Sar commands that will make you a Linux master Super practical! Sar commands that will make you a Linux master Mar 01, 2024 am 08:01 AM

1. Overview The sar command displays system usage reports through data collected from system activities. These reports are made up of different sections, each containing the type of data and when the data was collected. The default mode of the sar command displays the CPU usage at different time increments for various resources accessing the CPU (such as users, systems, I/O schedulers, etc.). Additionally, it displays the percentage of idle CPU for a given time period. The average value for each data point is listed at the bottom of the report. sar reports collected data every 10 minutes by default, but you can use various options to filter and adjust these reports. Similar to the uptime command, the sar command can also help you monitor the CPU load. Through sar, you can understand the occurrence of excessive load

What is the correct way to restart a service in Linux? What is the correct way to restart a service in Linux? Mar 15, 2024 am 09:09 AM

What is the correct way to restart a service in Linux? When using a Linux system, we often encounter situations where we need to restart a certain service, but sometimes we may encounter some problems when restarting the service, such as the service not actually stopping or starting. Therefore, it is very important to master the correct way to restart services. In Linux, you can usually use the systemctl command to manage system services. The systemctl command is part of the systemd system manager

How to use LSOF to monitor ports in real time How to use LSOF to monitor ports in real time Mar 20, 2024 pm 02:07 PM

LSOF (ListOpenFiles) is a command line tool mainly used to monitor system resources similar to Linux/Unix operating systems. Through the LSOF command, users can get detailed information about the active files in the system and the processes that are accessing these files. LSOF can help users identify the processes currently occupying file resources, thereby better managing system resources and troubleshooting possible problems. LSOF is powerful and flexible, and can help system administrators quickly locate file-related problems, such as file leaks, unclosed file descriptors, etc. Via LSOF Command The LSOF command line tool allows system administrators and developers to: Determine which processes are currently using a specific file or port, in the event of a port conflict

Artifact in Linux: Principles and Applications of eventfd Artifact in Linux: Principles and Applications of eventfd Feb 13, 2024 pm 08:30 PM

Linux is a powerful operating system that provides many efficient inter-process communication mechanisms, such as pipes, signals, message queues, shared memory, etc. But is there a simpler, more flexible, and more efficient way to communicate? The answer is yes, that is eventfd. eventfd is a system call introduced in Linux version 2.6. It can be used to implement event notification, that is, to deliver events through a file descriptor. eventfd contains a 64-bit unsigned integer counter maintained by the kernel. The process can read/change the counter value by reading/writing this file descriptor to achieve inter-process communication. What are the advantages of eventfd? It has the following features

See all articles