zoukankan      html  css  js  c++  java
  • 在windows上使用symfony创建简易的CMS系统(一)

    http://blog.csdn.net/kunshan_shenbin/article/details/7164675

    参考自:http://xsymfony.801.cxne.net/forum.php?mod=viewthread&tid=12&rpid=459&page=1

    在创建项目之前,首先需要搭建symfony发开环境。http://blog.csdn.net/kunshan_shenbin/article/details/7162243

    1. 创建工作目录,生成项目文件

    >md cms

    >cd cms

    >symfony generate:project cms

    >symfony generate:app frontend

    >symfony generate:app backend

    2. Apache下配置项目(新建虚拟主机)

    [html] view plaincopy
     
    1. <VirtualHost *:1300>  
    2.     DocumentRoot "D:WorkPHPcmsweb"  
    3.     DirectoryIndex index.php  
    4.     <Directory "D:WorkPHPcmsweb">  
    5.         AllowOverride All  
    6.         Allow from All  
    7.     </Directory>  
    8.   
    9.     Alias /sf D:xamppphpdatasymfonywebsf  
    10.     <Directory "D:xamppphpdatasymfonywebsf">  
    11.         AllowOverride All  
    12.         Allow from All  
    13.     </Directory>  
    14. </VirtualHost>  

    注意:

    以上配置需要添加在httpd-vhosts.conf文件中,并在httpd.conf中打开对相应端口的监听。

    当然,我们也可以通过修改hosts文件添加相应的域名解析。这里略过( 使用localhost ) 。

    重启Apache后,通过访问http://localhost:1300/ 可以看到symfony工程欢迎页面。


    从这里开始,我们可以选择一个顺手的IDE打开工程,以便更好的发开项目。

    3. 配置并创建数据库

    打开工程下config中的databases.yml文件,修改数据库连接的参数。

    [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.   
    4. all:  
    5.   doctrine:  
    6.     class: sfDoctrineDatabase  
    7.     param:  
    8.       dsn:      mysql:host=localhost;dbname=cms  
    9.       username: root  
    10.       password: root  


    定义schema ( cms/config/doctrine/schema.yml )

    [html] view plaincopy
     
    1. Category:  
    2.   columns:  
    3.     name: string(50)  
    4.     description: string(1000)  
    5.       
    6. Content:  
    7.   actAs:  
    8.     Timestampable: ~  
    9.   columns:  
    10.     title: string(255)  
    11.     body: clob  
    12.     view_count: integer  
    13.     recommend_level:  
    14.       type: enum  
    15.       values: [0, 1, 2]  
    16.       default: 2  
    17.     category_id: integer  
    18.   relations:  
    19.     Category:  
    20.       local: category_id  
    21.       foreign: id  
    22.       foreignAlias: Contents  
    23.         
    24. Comment:  
    25.   columns:  
    26.     body: clob  
    27.     user_id: integer  
    28.     content_id: integer  
    29.   relations:  
    30.     Content:  
    31.       local: content_id  
    32.       foreign: id  
    33.       foreignAlias: Comments  


    运行如下指令:

    >symfony doctrine:build --all

    4. 导入测试数据

    打开cms/data/fixtures/fixtures.yml文件,输入测试数据

    [html] view plaincopy
     
    1. # # Populate this file with data to be loaded by your ORM's *:data-load task.  
    2. # # You can create multiple files in this directory (i.e. 010_users.yml,  
    3. # # 020_articles.yml, etc) which will be loaded in alphabetical order.  
    4. # #   
    5. # # See documentation for your ORM's *:data-load task for more information.  
    6. #   
    7. # User:  
    8. #   fabien:  
    9. #     username: fabien  
    10. #     password: changeme  
    11. #     name:     Fabien Potencier  
    12. #     email:    fabien.potencier@symfony-project.com  
    13. #   kris:  
    14. #     username: Kris.Wallsmith  
    15. #     password: changeme  
    16. #     name:     Kris Wallsmith  
    17. #     email:    kris.wallsmith@symfony-project.com  
    18.   
    19. Category:  
    20.   c1:  
    21.     name: 巴西  
    22.     description: 南美球队  
    23.   c2:  
    24.     name: 英国  
    25.     description: 欧洲球队  
    26.   c3:  
    27.     name: 加纳  
    28.     description: 非洲球队  
    29.       
    30. Content:  
    31.   t1:  
    32.     title: 卡卡助攻  
    33.     body: ......  
    34.     view_count: 6  
    35.     recommend_level: 0  
    36.     Category: c1  
    37.     Comments: [m1, m2]  
    38.   t2:  
    39.     title: 鲁尼没有大作为  
    40.     body: ......  
    41.     view_count: 10  
    42.     recommend_level: 1  
    43.     Category: c2  
    44.       
    45. Comment:  
    46.   m1:  
    47.    body: 很赞  
    48.   m2:  
    49.    body: 太不尽人意了。  

    运行如下指令:

    > symfony doctrine:data-load

    5. 接下来我们开始着手生成后台的管理页面:

    >symfony doctrine:generate-admin backend Category

    >symfony doctrine:generate-admin backend Content

    >symfony doctrine:generate-admin backend Comment

    通过如下地址访问页面(开发环境入口)

    http://localhost:1300/backend_dev.php/category

    http://localhost:1300/backend_dev.php/content

    http://localhost:1300/backend_dev.php/comment

    然后运行如下指令添加css等样式资源:

    >symfony plugin:publish-assets

    再次访问后页面会比原来漂亮很多。

  • 相关阅读:
    Windows server 2016 解决“无法完成域加入,原因是试图加入的域的SID与本计算机的SID相同。”
    Windows Server 2016 辅助域控制器搭建
    Windows Server 2016 主域控制器搭建
    Net Framework 4.7.2 覆盖 Net Framework 4.5 解决办法
    SQL SERVER 2012更改默认的端口号为1772
    Windows下彻底卸载删除SQL Serever2012
    在Windows Server2016中安装SQL Server2016
    SQL Server 创建索引
    C#控制台或应用程序中两个多个Main()方法的设置
    Icon cache rebuilding with Delphi(Delphi 清除Windows 图标缓存源代码)
  • 原文地址:https://www.cnblogs.com/walter371/p/4664788.html
Copyright © 2011-2022 走看看