http://blog.csdn.net/kunshan_shenbin/article/details/7164675
Reference from: http://xsymfony.801.cxne.net/forum.php?mod=viewthread&tid=12&rpid=459&page=1
Before you create a project, you first need to build a symfony environment. http://blog.csdn.net/kunshan_shenbin/article/details/7162243
1. Create a working directory and build a project file
>MD CMS
>CD CMS
>symfony Generate:project CMS
>symfony Generate:app frontend
>symfony Generate:app Backend
2. Apache under configuration item (new virtual host)
[HTML]View Plaincopy
- <VirtualHost *:1300>
- DocumentRoot "D:\Work\PHP\cms\web"
- DirectoryIndex index.php
- <Directory "D:\Work\PHP\cms\web">
- AllowOverride All
- Allow from all
- </Directory>
- ALIAS/SF D:\XAMPP\PHP\DATA\SYMFONY\WEB\SF
- <Directory "D:\XAMPP\PHP\DATA\SYMFONY\WEB\SF">
- AllowOverride All
- Allow from all
- </Directory>
- </VirtualHost>
Attention:
The above configuration needs to be added to the httpd-vhosts.conf file, and the corresponding port is opened for listening in httpd.conf.
Of course, we can also add the corresponding domain name resolution by modifying the Hosts file. Skip here (use localhost).
After restarting Apache, you can see the Symfony Project welcome page by visiting Http://localhost:1300/.
From here, we can choose a handy IDE to open the project in order to get a better start.
3. Configure and create a database
Open the Databases.yml file in the project config, and modify the parameters of the database connection.
[HTML]View Plaincopy
- # you can find more information about this file on the symfony website:
- # http:// www.symfony-project.org/reference/1_4/en/07-Databases
- &NBSP;&NBSP;
- All :
- &NBSP;&NBSP;DOCTRINE:&NBSP;&NBSP;
- class: sfdoctrinedatabase
- &NBSP;&NBSP;&NBSP;&NBSP;PARAM:&NBSP;&NBSP;
- dsn: mysql:host =localhost; dbname=CMS&NBSP;&NBSP;
- &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;USERNAME:&NBSP;ROOT&NBSP;&NBSP;
- password: root
Define schema (CMS/CONFIG/DOCTRINE/SCHEMA.YML)
[HTML]View Plaincopy
- Category:
- Columns
- Name:string (50)
- Description:string (1000)
- Content:
- ActAs:
- Timestampable: ~
- Columns
- Title:string (255)
- Body:clob
- View_count:integer
- Recommend_level:
- Type:enum
- Values: [0, 1, 2]
- Default:2
- Category_id:integer
- Relations:
- Category:
- local:category_id
- Foreign:id
- Foreignalias:contents
- Comment:
- Columns
- Body:clob
- User_id:integer
- Content_id:integer
- Relations:
- Content:
- local:content_id
- Foreign:id
- Foreignalias:comments
Run the following command:
>symfony Doctrine:build--all
4. Import test Data
Open the Cms/data/fixtures/fixtures.yml file and enter the test data
[HTML]View Plaincopy
- # # Populate This file with the data to is loaded by your ORM ' s *:d ata-load task.
- # # can create multiple files in this directory (i.e. 010_USERS.YML,
- # # 020_ARTICLES.YML, etc) which'll be loaded in alphabetical order.
- # #
- # # See documentation for your ORM's *:d ata-load task for more information.
- #
- # User:
- # Fabien:
- # Username:fabien
- # Password:changeme
- # Name:fabien Potencier
- # email: [Email protected]
- # kris:
- # Username:Kris.Wallsmith
- # Password:changeme
- # Name:kris Wallsmith
- # email: [Email protected]
- Category:
- C1:
- Name: Brazil
- Description: South American team
- C2:
- Name: United Kingdom
- Description: European Team
- C3:
- Name: Ghana
- Description: African team
- Content:
- T1:
- Title: Kaka assists
- Body: ...
- View_count:6
- recommend_level:0
- Category:c1
- Comments: [M1, M2]
- T2:
- Title: Wayne Rooney has no big act
- Body: ...
- View_count:10
- Recommend_level:1
- Category:c2
- Comment:
- M1:
- Body: Great
- M2:
- Body: It's too disappointments.
Run the following command:
> Symfony doctrine:data-load
5. Next we start to build the admin page in the background:
>symfony Doctrine:generate-admin Backend Category
>symfony Doctrine:generate-admin Backend Content
>symfony Doctrine:generate-admin Backend Comment
Access the page from the following address (development environment portal)
Http://localhost:1300/backend_dev.php/category
Http://localhost:1300/backend_dev.php/content
Http://localhost:1300/backend_dev.php/comment
Then run the following command to add style resources such as CSS:
>symfony plugin:publish-assets
After the visit, the page will be much prettier than the original.
Create a simple CMS system using Symfony on Windows (i)