Symfony2 Framework Combat Tutorial-First day: Creating a Project

Source: Internet
Author: User

Symfony2 's tutorial is very detailed, but not too close to the novice. Novice want to fully understand the content of the Symfony2 document, need to have some work experience on the Internet development, otherwise there is always a kind of look not quite understand, read and do not know where to start the feeling. If you have this feeling, hope this article can let you get started quickly, the purpose of this article is to let Symfony2 novice, even PHP Novice can quickly start a specific project.

The focus of this series is to lead the novice to use the Symfony2 framework , if you want to learn about the Symfony2 component , you can read my translation Symfony2 Project team boss's series of tutorials, creating your own PHP framework with SYMFONY2 components 》

This series of source code is located in Https://coding.net/u/chrisyue/p/symfony2-framework-tutorial/git, but because the source code already contains various additions to modify the refactoring after the code, do not see the intermediate process, It is recommended to look at all chapters after completion, or as a reference later.

Preparatory work

Download and install PHP. Symfony2 required to run above the PHP5.3 version. However, with the PHP version of the upgrade, the function is also more and more rich, the speed is also improved, so I recommend the latest stable version. With Web server in PHP5.5, it means you don't even need services like Nginx or Apache to start your project quickly, so yes, this tutorial is about PHP5.6. Isn't it 5.5?) for an example to explain.

Ensure that PHP is in the path directory.

This article mainly explains how to use SYMFONY2 to develop projects quickly. So do not elaborate on the installation of PHP knowledge, these knowledge points on the Internet is easy to find.

Initialize Project

This tutorial I try to follow the way Windows/*nix can be run to explain.

Thanks to Symfony installer, we can now easily initialize a Symfony2 project. But first, you have to have a symfony installer.

Create a directory: such as WWW, and then install Symfony installer in this directory (note $ for the command prompt, just to look good, the actual operation is not required to enter $, no longer repeat):

12 $ php -R "ReadFile (' Http://symfony.com/installer ');" > symfony. Phar

Then run the following command to confirm that the file is executable

12 $ php symfony. Phar

If the file is undamaged, the version number of the Symfony installer should be displayed, along with a brief description of how to use the Symfony installer:

123456789101112131415161718192021222324 Symfony Installer (0.5.0) =========================the Official installer to start new projects c22>based on the Symfony Full-stack framework. to create a new project called blog in the Current directory using the latest stable version of Symfony, execute the following command< c12>: $ symfony. Phar new blog to base your project on a specific Symfony version, Append the version Number at the end of the command: $ symfony. Phar new blog 2.5.6 Updating The Symfony Installer ------------------------------ New versions of the Symfony Installer is released regularly. To update your Installer version, execute the following command: $ symfony. Phar Self-update

Next, we use Symfony.phar to create a project. Here we are going to do a news aggregator site, the project is called News:

12 $ php symfony. Phar New news

If there is no problem with the network, a progress bar should appear, at which point Symfony Installer creates the news directory in the current directory, initializes the working directory of the Symfony2 framework, and downloads the required third-party PHP libraries.

123 downloading Symfony. . 85.81 KB/4.89 MB ▓?????????????????????????????????????????? 1%

When the download is complete, go to the news directory and we can see Symfony installer as the working directory we initialized. Here we can remove some files that are not necessary for development (UPGRADE-***,LICENSE,README.MD).

Without an accident, we can open a Web server listener on localhost:8000 with a command (note: This command can only run on the PHP5.5 version):

12 $ php app/console server:start localhost:8000

Access in the browser http://localhost:8000 , you should be able to see the Symfony framework after the installation of the Welcome page

Note: If you do not visit the homepage, it is likely that you are installing the Symfony 2.7 version. This version of the demo page has been removed because the Symfony team feels too simplistic.

At this point, the SYMFONY2 project initialization has been completed

We can use the SYMFONY2 Framework's own scripting tool to verify that the current environment is running smoothly enough symfony:

12 $ php app/check. PHP

Like the results I showed here, I recommend installing the intl extension

In addition, we can also see the hint that because the command line loading may be different from the php.ini Web server load (the common php-fpm general is not the php same file loaded under the command line), it is recommended to php.ini view the review in the browser /config.php .

Symfony2 Framework Combat Tutorial-First day: Creating a Project

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.