当前位置: 首页 > 工具软件 > OpenPNE > 使用案例 >

openPNE创建项目

董飞
2023-12-01
==================================================================================使在cmd命令符下找到php命令
打开“我的电脑”->“属性”->“高级”->“环境变量”->“系统变量”->“path”,编辑其值,在前面
增加下面的路径地址:
D:\wamp\bin\php\php5.3.0; ===========php编译安装目录
将php.ini复制到C:\Windows 目录下


==================================================================================symfony简单的建程序
将下载好的symfony压缩包解压缩到www文件夹下起名symfony
命令行输入
e:打开E盘根目录
cd..\.. ===========返回上两级,或打开指定目录
cd wamp\www\symfony ===========打开指定目录
php data\bin\symfony -V ===========查询symfony版本信息
php data\bin\symfony generate:project newProject ===========在www\symfony文件夹下生成一个名叫newProject的新项目
php data\bin\symfony generate:app myApp ===========在该项目的APPS文件夹下生成一个名叫myApp新程序
php data\bin\symfony generate:module myApp myModule ===========在myApp程序文件夹下建立一个名叫myModule的新模块
php调用的symfony命令打开的是相对当前目录存放symfony命令的目录
在动作类中写的动作方法与对应模板的访问路径 mymodule模块名 myAction动作方法名
http://localhost/symfony/web/myApp_dev.php/mymodule/myAction
symfony学习网站
http://www.symfony-project.org/jobeet/1_2/Propel/zh_CN/01


==================================================================================OpenPNE 安装
将下载好的压缩包解压缩到服务器目录
查找 ProjectConfiguration.class.php.sample改名成ProjectConfiguration.class.php
Apache服务打开rewrite模块
cmd命令符下打开openPNE所在文件夹,输入
php symfony openpne:install
PHP的APC扩展:如有需要将115中的php_apc.dll下载到wamp\bin\php\php5.3.0\ext目录下
打开php扩展的php_apc,打开php.ini,找到extension=php_apc.dll并在下一行添加
apc.enabled=0
apc.shm_segments=0
apc.enable_cli=0
如果根目录有cache文件夹把cache中的内容清空


==================================================================================创建一个程序
cmd输入
php symfony opGenerate:plugin opVotePlugin ===========创建一个vote插件程序
php symfony opGenerate:app opVotePlugin pc_frontend ===========为vote插件程序创建电脑前台文件夹
php symfony opGenerate:module opVotePlugin pc_frontend vote ===========在vote插件程序电脑前台文件夹内创建vote模块
php symfony cc ===========清除一次缓存
此时可以通过http://localhost/openpne/web/vote来访问刚建立插件模块的默认index动作页


==================================================================================action动作及访问权限
在plugins\opVotePlugin\lib\actions目录下创建一个opVotePluginVoteActions.class.php文件
文件中写类class opVotePluginVoteActions extends sfActions{}
然后在opVotePlugin\apps\pc_frontend\modules\vote\actions\actions.class.php文件中的类继承刚才写的类
class voteActions extends opVotePluginVoteActions{}
不仅电脑前台pc_frontend文件夹内,在opVotePlugin\apps下的所有手机电脑前后台模块动作都可以继承这个类,实现一个类管理多个前端
建立plugins\opVotePlugin\apps\pc_frontend\modules\vote\config\security.yml文件然后输入
all:
is_secure: on
credentials: SNSMember
表示此模块需要验证,只有会员才能访问
在opVotePluginVoteActions类中写一个动作
public function executeShow(sfWebRequest $request){}
然后创建plugins\opVotePlugin\apps\pc_frontend\modules\vote\templates\showSuccess.php
执行一次命令php symfony cc
至此可以通过http://localhost/openpne/web/vote/show来访问刚才创建的动作页面


==================================================================================建立数据库表
创建plugins/opVotePlugin/config/doctrine/schema.yml文件,输入
options:
charset: utf8

VoteQuestion:
actAs: [Timestampable]
columns:
id: { type: integer(4), primary: true, autoincrement: true }
member_id: { type: integer(4), notnull: true }
title: { type: string(140), notnull: true }
body: { type: string }
relations:
Member: { onDelete: cascade }

VoteQuestionOption:
columns:
id: { type: integer(4), primary: true, autoincrement: true }
vote_question_id: { type: integer(4), notnull: true }
body: { type: string(140), notnull: true }
relations:
VoteQuestion: { onDelete: cascade, foreignAlias: VoteQuestionOptions }

VoteAnswer:
actAs: [Timestampable]
columns:
id: { type: integer(4), primary: true, autoincrement: true }
member_id: { type: integer(4), notnull: true }
vote_question_id: { type: integer(4), notnull: true }
vote_question_option_id: { type: integer(4), notnull: true }
body: { type: string }
relations:
Member: { onDelete: cascade }
VoteQuestion: { onDelete: cascade, foreignAlias: VoteAnswers }
VoteQuestionOption: { onDelete: cascade, foreignAlias: VoteAnswers }
表示分别创建了vote_question,vote_question_option,vote_answer三个表其中的relations表示设立外键关联
此时执行命令php symfony openpne:install将重新安装openPNE并创建前面三张表
之后再执行一次php symfony doctrine:build --all --and-load 重新插入数据


==================================================================================路由规则
创建plugins/opVotePlugin/lib/routing/opVotePluginFrontendCollection.class.php
输入
<?php
class opVotePluginFrontendRouteCollection extends sfRouteCollection
{
public function __construct(array $options)
{
parent::__construct($options);
$this->routes = array(
'vote_list' => new sfRequestRoute( /*例如<form method="post" action='<?php echo url_for("@vote_list?id=1");?>'>表单通过此来指定提交到哪个动作并传一个id参数*/
'/vote', //http://localhost/openpne/web后接的部分来访问此动作
array('module' => 'vote', 'action' => 'index'), //指定以上规则所属的模块与动作
array('sf_method' => array('get'))
),
'vote_new' => new sfRequestRoute(
'/vote/new',
array('module' => 'vote', 'action' => 'new'),
array('sf_method' => array('get'))
),
'vote_create' => new sfRequestRoute(
'/vote/create',
array('module' => 'vote', 'action' => 'create'),
array('sf_method' => array('post'))
),
'vote_edit' => new sfDoctrineRoute(
'/vote/edit/:id', //http://localhost/openpne/web后接的部分加参数来访问此动作如http://localhost/openpne/web/vote/edit/5 5为要传的值
array('module' => 'vote', 'action' => 'edit'),
array('id' => '\d+', 'sf_method' => array('get')),
array('model' => 'VoteQuestion', 'type' => 'object')
),
'vote_update' => new sfDoctrineRoute(
'/vote/update/:id',
array('module' => 'vote', 'action' => 'update'),
array('id' => '\d+', 'sf_method' => array('post')),
array('model' => 'VoteQuestion', 'type' => 'object')
),
'vote_show' => new sfDoctrineRoute(
'/vote/show/:id',
array('module' => 'vote', 'action' => 'show'),
array('id' => '\d+', 'sf_method' => array('get')),
array('model' => 'VoteQuestion', 'type' => 'object')
),
'vote_post' => new sfDoctrineRoute(
'/vote/post/:id',
array('module' => 'vote', 'action' => 'post'),
array('id' => '\d+', 'sf_method' => array('post')),
array('model' => 'VoteQuestion', 'type' => 'object')
),
'vote_delete_confirm' => new sfDoctrineRoute(
'/vote/delete/:id',
array('module' => 'vote', 'action' => 'deleteConfirm'),
array('id' => '\d+', 'sf_method' => array('get')),
array('model' => 'VoteQuestion', 'type' => 'object')
),
'vote_delete' => new sfDoctrineRoute(
'/vote/delete/:id',
array('module' => 'vote', 'action' => 'delete'),
array('id' => '\d+', 'sf_method' => array('post')),
array('model' => 'VoteQuestion', 'type' => 'object')
),
// no default
'vote_nodefaults' => new sfRoute(
'/vote/*',
array('module' => 'default', 'action' => 'error')
),
);
}
}
?>
创建plugins/opVotePlugin/apps/pc_frontend/config/routing.yml
输入
vote:
class: opVotePluginFrontendRouteCollection
options: { name: vote }
指定由哪个类来设定路由规则
输入命令php symfony cc
输入命令php symfony app:routes pc_frontend 查看路由是否设定成功
不创建opVotePluginFrontendCollection.class.php与routing.yml文件也可,将按默认路由访问

转载于:https://www.cnblogs.com/dreamhome/archive/2011/11/13/2247541.html

 类似资料: