Create a simple CMS system using Symfony on Windows (i)

Source: Internet
Author: User

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
  1. <VirtualHost *:1300>
  2. DocumentRoot "D:\Work\PHP\cms\web"
  3. DirectoryIndex index.php
  4. <Directory "D:\Work\PHP\cms\web">
  5. AllowOverride All
  6. Allow from all
  7. </Directory>
  8. ALIAS/SF D:\XAMPP\PHP\DATA\SYMFONY\WEB\SF
  9. <Directory "D:\XAMPP\PHP\DATA\SYMFONY\WEB\SF">
  10. AllowOverride All
  11. Allow from all
  12. </Directory>
  13. </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
    1. # you can find more information  about this file on the symfony website:  
    2. # http:// www.symfony-project.org/reference/1_4/en/07-Databases  
    3. &NBSP;&NBSP;
    4. All :   
    5. &NBSP;&NBSP;DOCTRINE:&NBSP;&NBSP;
    6.     class:  sfdoctrinedatabase  
    7. &NBSP;&NBSP;&NBSP;&NBSP;PARAM:&NBSP;&NBSP;
    8.       dsn:      mysql:host =localhost; dbname=CMS&NBSP;&NBSP;
    9. &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;USERNAME:&NBSP;ROOT&NBSP;&NBSP;
    10.       password: root  


Define schema (CMS/CONFIG/DOCTRINE/SCHEMA.YML)

[HTML]View Plaincopy
  1. Category:
  2. Columns
  3. Name:string (50)
  4. Description:string (1000)
  5. Content:
  6. ActAs:
  7. Timestampable: ~
  8. Columns
  9. Title:string (255)
  10. Body:clob
  11. View_count:integer
  12. Recommend_level:
  13. Type:enum
  14. Values: [0, 1, 2]
  15. Default:2
  16. Category_id:integer
  17. Relations:
  18. Category:
  19. local:category_id
  20. Foreign:id
  21. Foreignalias:contents
  22. Comment:
  23. Columns
  24. Body:clob
  25. User_id:integer
  26. Content_id:integer
  27. Relations:
  28. Content:
  29. local:content_id
  30. Foreign:id
  31. 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
  1. # # Populate This file with the data to is loaded by your ORM ' s *:d ata-load task.
  2. # # can create multiple files in this directory (i.e. 010_USERS.YML,
  3. # # 020_ARTICLES.YML, etc) which'll be loaded in alphabetical order.
  4. # #
  5. # # See documentation for your ORM's *:d ata-load task for more information.
  6. #
  7. # User:
  8. # Fabien:
  9. # Username:fabien
  10. # Password:changeme
  11. # Name:fabien Potencier
  12. # email: [Email protected]
  13. # kris:
  14. # Username:Kris.Wallsmith
  15. # Password:changeme
  16. # Name:kris Wallsmith
  17. # email: [Email protected]
  18. Category:
  19. C1:
  20. Name: Brazil
  21. Description: South American team
  22. C2:
  23. Name: United Kingdom
  24. Description: European Team
  25. C3:
  26. Name: Ghana
  27. Description: African team
  28. Content:
  29. T1:
  30. Title: Kaka assists
  31. Body: ...
  32. View_count:6
  33. recommend_level:0
  34. Category:c1
  35. Comments: [M1, M2]
  36. T2:
  37. Title: Wayne Rooney has no big act
  38. Body: ...
  39. View_count:10
  40. Recommend_level:1
  41. Category:c2
  42. Comment:
  43. M1:
  44. Body: Great
  45. M2:
  46. 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)

Related Article

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.