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下配置项目(新建虚拟主机)

  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>

注意:

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

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

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

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

3. 配置并创建数据库

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

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

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

  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

运行如下指令:

>symfony doctrine:build --all

4. 导入测试数据

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

  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. Category:
  19. c1:
  20. name: 巴西
  21. description: 南美球队
  22. c2:
  23. name: 英国
  24. description: 欧洲球队
  25. c3:
  26. name: 加纳
  27. description: 非洲球队
  28. Content:
  29. t1:
  30. title: 卡卡助攻
  31. body: ......
  32. view_count: 6
  33. recommend_level: 0
  34. Category: c1
  35. Comments: [m1, m2]
  36. t2:
  37. title: 鲁尼没有大作为
  38. body: ......
  39. view_count: 10
  40. recommend_level: 1
  41. Category: c2
  42. Comment:
  43. m1:
  44. body: 很赞
  45. m2:
  46. 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上使用symfony创建简易的CMS系统(一)的更多相关文章

  1. 004.Create a web app with ASP.NET Core MVC using Visual Studio on Windows --【在 windows上用VS创建mvc web app】

    Create a web app with ASP.NET Core MVC using Visual Studio on Windows 在 windows上用VS创建mvc web app 201 ...

  2. 在Windows上使用Docker 创建MongoDB 副本集的极简方法(翻译)

    这篇博客介绍下在Windows上使用Docker 创建MongoDB 三节点副本集的最简单的方法.以下命令需要Docker for Windows并使用Linux 容器. 1: 为每个节点创建数据卷 ...

  3. 用dedecms自定义表单创建简易自助预约系统

    建站往往需要根据客户的需求来增加相应的功能,比如预约.平时用比较多的是织梦系统,那么如何用dedecms自定义表单创建简易自助预约系统呢? 进入dedecms后台,左侧菜单中依次点击“核心” - 频道 ...

  4. 【python安装】Windows上安装和创建python开发环境

    1. 在 windows10 上安装python开发环境 Linux和Mac OS都自带python环境,但是Windows没有,所以需要自行安装. 第1步:访问 python官网,下载Windows ...

  5. windows上通过vnc连接虚拟机中linux系统

    首先要在虚拟机中安装vnc. 虚拟机的设置中要启用VNC连接. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHdzc2c=/font/5a6L5L2T/ ...

  6. 峰回路转:去掉 DbContextPool 后 Windows 上的 .NET Core 版博客表现出色

    今天早上,我们修改了博客程序中的1行代码,将 services.AddDbContextPool 改为 services.AddDbContext ,去掉 DbContextPool . 然后奇迹出现 ...

  7. Windows Azure 上的 Symfony,适用于 PHP 开发者的强大组合

     发布于 2014-06-13 作者 陈 忠岳 Symfony 是针对 PHP 开发者的流行开源 Web 应用框架.现在,您可以更轻松地在 Windows Azure 上使用它,这都归功于 Ben ...

  8. 002.Create a web API with ASP.NET Core MVC and Visual Studio for Windows -- 【在windows上用vs与asp.net core mvc 创建一个 web api 程序】

    Create a web API with ASP.NET Core MVC and Visual Studio for Windows 在windows上用vs与asp.net core mvc 创 ...

  9. windows上通过secureCRT和putty创建密钥登录

    前面介绍了linux的ssh远程登录协议和ssh无password登录方式.这里在windows下通过secureCRT和putty登录linux来看一下详细的密钥创建,配置和登录.也算做个备忘录吧. ...

随机推荐

  1. win7突然无法启动(以前可以启动的,电脑是ubuntu+win7双系统)

    这里 有个解决办法是将win7的menuentry里的chainloader +1改为ntldr /bootmgr,但是这个解决办法是基于把Boot Loader指定在/dev/sda1里了,即win ...

  2. 【Spring 1】Spring简介

    一.Spring简介 首先,Spring框架是由于软件开发的复杂性而创建的.Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spring的用途不仅仅限于服务器端的开 ...

  3. angular service讲解

    controller是相对独立的,也就是说,两个controller之间,内存是不共享的,这个controller是无法访问其他其他controller的属性或者方法的; 以前,我都是通过localS ...

  4. 华为OJ—火车进站(栈,字典排序)

    http://career-oj.huawei.com/exam/ShowSolution?method=SolutionApp&id=2282 给定一个正整数N代表火车数量,0<N&l ...

  5. backBarButtonItem 颜色/文字修改

    iOS7之后. 默认的返回按钮字体颜色是蓝色的, 显示内如是父VC(上一级界面)的title 如果要做修改, 可以通过下面的办法: 1. 修改字体颜色 (1) 在plist里面, 加上View con ...

  6. HLS入门收集(1)

    使用HLS各种问题 关于求指数函数 exp(x) 在HLS中使用exp(x),也就是指数函数.不能导出RTL到EDK也就是Pcore  只能导出为VIVADO IP:相关解释:见官方论坛 http:/ ...

  7. (四)、 nodejs中Async详解之一:流程控制

    为了适应异步编程,减少回调的嵌套,我尝试了很多库.最终觉得还是async最靠谱. 地址:https://github.com/caolan/async Async的内容分为三部分: 流程控制:简化十种 ...

  8. 使用C#中JavaScriptSerializer类将对象转换为Json格式数据

    将对象转换为json格式字符串: private JavaScriptSerializer serializer = new JavaScriptSerializer(); protected voi ...

  9. 调用WCF Data Service的几点Tips

    使用Linq实现sql in statement的时候,用EF的时候可以通过Contains.Exists的方法实现.但是在使用WCF Data Service的context的时候,会报不支持该方法 ...

  10. CentOS下安装LNMP(LINUX+NGINX+MYSQL+PHP)环境

    一.安装Nginx最新版 首先查看是否有安装源包 yum list nginx  (或yum info nginx) 如果没有则 vi /etc/yum.repos.d/nginx.repo #添加如 ...