The example in this article describes how to create a project using the Symfony command. Share to everyone for your reference, as follows:
Overview
This section describes a reasonable structural framework for a symfony project and initializes the project structure with the Symfony command.
Introduced
In Symfony, a project is a set of services and effective operations under a specified domain name, sharing the same project model.
In a project, the actions in the application are a set of logic, and each application can run independently and with no interference from other applications in the same project.
In most cases, a project will contain two apps, one for the foreground display, one for background processing, and the same database for use. Of course you can also include many small sites in a project, each of which is a different application. Note hyperlinks that are used between different apps must use absolute paths.
Each application is a set of modules, each of which is responsible for a particular function. A module typically uses a page or a set of pages for similar functions. For example, the module can be home, articles, help, ShoppingCart, account, and so on.
Module function: Each module has their own functions, such as shoppingcart (shopping cart) module to have Add, show (show) and update (updated) features. The behavior of a feature can be viewed as a page behavior in a typical Web application.
If the level of a new project is too many, then it is easy to group all the functions in the module so that the file structure can be kept simple. When the application is more complex, the functions can be organized in logical modules.
Each app can run in a different environment, such as a different configuration or database. In general, each new application will run in three environments (development, testing, and end products). Each application can run in more environments if required, and only the configuration accessories need to be modified in different environments.
For example, a test environment needs to log warnings and errors, and an end-product environment will only need to log errors. Cache acceleration is not usually turned on in the development environment, but needs to be turned on in test and final product environments. The development environment and test environment may require data to be tested and stored in the remote database of the final product. All environments can coexist on a single machine, and typically only the final product environment is available on the product server.
Note: If you are using Symfony in sandbox (sandbox), you do not need to set up a project or application, a project called ' Sf_sandbox ' has been prepared inside the sandbox and an app named ' Frontend '. You do not need to set up a Web server, just put your program in the web/root directory.
Pake
Symfony uses specialized tools Pake to manage projects, applications, and modules. Pake is a PHP tool, similar to the Rake command (this is a tool for converting make commands 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, all of the operations will become very simple.
To get a list of all valid administrative operations commands, simply enter it in your project directory:
$ symfony-t
The CLI (command-line action) Task Scheduler is used during the pre-phase of a project. A complete description of CLI task scheduling refer to the CLI chapter.
Project Settings
Before you start, you must create a new directory to store your project:
$ mkdir/home/steve/myproject
Then, start initializing the project to generate the original files and directories, simple input:
$ 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.
Apply Settings
The project has not been completed yet, and it needs at least one application. First use the Symfony Init-app command to initialize an app, using the arguments followed by the command to name the app:
$ symfony Init-app MyApp
This creates a MyApp directory in the apps/folder at the root of the project, which contains a default app configuration and a set of catalog files for your site:
apps/
myapp/
config/
i18n/
lib/
modules/
templates/
Some PHP files that act as front-end controllers in their default environments are also created under the Web directory of the project's root directory:
web/
index.php
myapp_dev.php
Index.php is the front-end controller for production new applications. Because when you create the first application in this project, Symfony creates a file that calls index.php, such as myapp.php (if you now add a new application called Mynewapp, The front controller of the new product will be named mynewapp.php). When you run the program in the development environment, the front-end controller myapp_dev.php is called.
Note: If you read the introduction carefully, you may be surprised at the location of the myapp_test.php file. In fact, the test environment is used to unit test the artifacts of your application, and it does not require a front-end controller. You can refer to the Unit Test section for more detailed information.
From now on, the/home/steve/myproject/directory will be the root directory of the project. The path to the root directory has been saved as a Sf_root_dir constant, defined in the index.php file, and we will use this constant name instead of the actual path to avoid confusing readers who are not Steve (note: Because the author puts the item in the/home/steve/ Myprojetc directory, this path may be different for each person, so use constant sf_root_dir instead of the actual path.
Web server Settings
In order to access and test the new application, you need to configure the Web server. Here is an example of Apache that adds a new virtual host to the httpd.conf configuration file:
allowoverride 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 above configuration needs to be replaced by your Pear library directory. For example: In the *nix system, you can enter:
Alias /sf /usr/local/lib/php/data/symfony/web/sf
You can find more information about the Pear directory in the installation section.
After restarting the Apache service, you will be able to see the page that invokes the newly created application, just enter the following path in the address bar of a standard Web browser:
http://myapp.example.com/index.php/
Or, use this path in debug mode:
http://myapp.example.com/myapp_dev.php/
Note: The Mod_rewrite module is used when Symfony displays the ' short Nice ' (smart) ' path. If your Apache version does not compile the Mod_rewrite module, you need to check the httpd.conf for the module mod_rewrite is dynamic module mode (DSO) installed, and confirm whether it is open (translator Note: About Apache Mod_ For the installation and use of the rewrite module, refer to the Apache documentation, which assumes that the reader already has this knowledge without too much explanation):
Addmodule mod_rewrite.cloadmodule Rewrite_module modules/mod_rewrite.so
You can learn more about the short path (smart URLs) in the Routing (routing) section.
Symfony compatible with other server configuration methods. You can also, for example, use aliases (alias) to access Symfony applications instead of virtual hosts. For more information on Web server configuration, please refer to the relevant section.
Module settings
Your new application is not exceptional, it lacks attractive features. If you want to add functionality, you need to use the module in it. Once again, the Symfony command is used, with the parameter init-module, followed by the application name and the name of the new module:
$ symfony init-module MyApp mymodule
The following tree structure is created:
modules/
mymodule/
actions/
config/
lib/
templates/
validate/
The new module can be used directly:
Http://myapp.example.com/index.php/mymodule
Then you need to make it work normally, edit the file myapp/modules/mymodule/templates/indexsuccess.php input:
Hello, World!
Save it, refresh the page just to see the content!
Source file version control (source versioning)
After the application settings are complete, it is recommended that you start source file versioning. Symfony support for CVS from the outset (translator Note: Version control system), it is recommended to use Subversion (Translator Note: A version control system software, using the CVS operating model, with the goal of replacing CVS). The following example lists some of the Subversion commands used to create a "warehouse" of a new project on a server where Subversion is installed (repository, where the source code is stored). For Windows users, it is recommended that clients use TORTOISESVN. For more information and command usage on source file versioning, refer to the Subversion documentation.
The following example assumes that $svnrep_dir is an environment variable that has already been defined. If you haven't defined it yet, you need to replace the $svnrep_dir variable with the actual path of the "warehouse".
Now let's start creating a new "warehouse" for the MyProject project:
$ svnadmin Create $SVNREP _dir/myproject
Then use this command to create a new "warehouse" of the basic organizational structure (planning), which contains trunks, tags and branches three directories:
[code]$ svn mkdir-m "layout creation" file:///$SVNREP _dir/myproject/trunk file:///$SVNREP _dir/myproject/tags file:/// $SVNREP _dir/myproject/branches[/code]
This will be the first version of you. You must now import the project's files, but not the temporary files such as caches and logs:
$ cd/home/steve/myproject$ rm-rf cache/*$ rm-rf log/*$ svn import-m "initial import". file:///$SVNREP _dir/myproject/trunk
Check the submitted file:
$ svn ls file:///$SVNREP _dir/myproject/trunk/
It looks pretty good. Now SVN "Warehouse" has recorded all the project file versions (and change history). This means that all files in the directory where the actual path is/home/steve/myproject are already recorded by the "Warehouse". To do this, first rename the MyProject directory name, and when everything is working, you can delete it and submit a checkout to the repository in the new directory:
$ cd/home/steve$ mv MyProject myproject.origin$ SVN co file:///$SVNREP _dir/myproject/trunk myproject$ ls myproject
Now you can work in a file in the/home/steve/myproject/directory and commit the changes to the repository. Do not forget to make some cleanup and delete the Myproject.origin directory, it is now useless.
There are some additional settings. When you submit a working directory to a "warehouse", some extra files are copied, like files in the cache and log directories in the project. So you need to specify an ignore list for this project in SVN. You also need to re-set the permissions of the cache/and log/directories to full control, and the files generated during the Access SVN will not be stored:
$ cd/home/steve/myproject$ svn propedit svn:ignore. $ chmod 777 cache$ chmod 777 Log
This invokes the default text editor set in SVN. If not, set Subversion's preferred editor as follows:
$ export svn_editor=
$ SVN propedit svn:ignore.
Add the MyProject subdirectory directly to the Ignore list in SVN, which is ignored when committing:
Cachelog
Save and then exit, so it's done.
It is hoped that this article is helpful to the PHP program design based on Symfony framework.