Rumah  >  Artikel  >  pembangunan bahagian belakang  >  用openPNE怎样才能创建一个项目

用openPNE怎样才能创建一个项目

醉折花枝作酒筹
醉折花枝作酒筹ke hadapan
2021-07-16 15:56:091980semak imbas

不知道你们有没有用过openPNE,其实我们可以使用openPNE创建过项目。今天我们就来介绍一下openPNE创建过项目的方法,有需要的可以参考参考。

用openPNE怎样才能创建一个项目

使在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动作方法名

OpenPNE 安装

将下载好的压缩包解压缩到服务器目录

查找 ProjectConfiguration..php.sample改名成ProjectConfiguration..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    ===========清除一次缓存

action动作及访问权限

在plugins\opVotePlugin\lib\actions目录下创建一个opVotePluginVoteActions..php文件

文件中写类class opVotePluginVoteActions  sfActions{}

然后在opVotePlugin\apps\pc_frontend\modules\vote\actions\actions..php文件中的类继承刚才写的类

voteActions  opVotePluginVoteActions{}

不仅电脑前台pc_frontend文件夹内,在opVotePlugin\apps下的所有手机电脑前后台模块动作都可以继承这个类,实现一个类管理多个前端

建立plugins\opVotePlugin\apps\pc_frontend\modules\vote\config\security.yml文件然后输入

all:

 is_secure: on

 credentials: SNSMember

表示此模块需要验证,只有会员才能访问

在opVotePluginVoteActions类中写一个动作

 executeShow(sfWebRequest ){}

然后创建plugins\opVotePlugin\apps\pc_frontend\modules\vote\templates\showSuccess.php

执行一次命令php symfony cc

建立数据库表

创建plugins/opVotePlugin/config/doctrine/schema.yml文件,输入

options:
  charset: utf8

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

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

VoteAnswer:
  actAs: [Timestampable]
  columns:
    id: { type: (4), primary: , autoincrement:  }
    member_id: { type: (4), notnull:  }
    vote_question_id: { type: (4), notnull:  }
    vote_question_option_id: { type: (4), notnull:  }
    body: { type:  }
  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..php

输入

<?php
 opVotePluginFrontendRouteCollection  sfRouteCollection
{
  __construct( )
  {
    parent::__construct();
->routes = (
      &#39;vote_list&#39; =>  sfRequestRoute(    
        &#39;/vote&#39;,                                    (&#39;module&#39; => &#39;vote&#39;, &#39;action&#39; => &#39;index&#39;),            (&#39;sf_method&#39; => (&#39;get&#39;))
      ),
      &#39;vote_new&#39; =>  sfRequestRoute(
        &#39;/vote/new&#39;,
(&#39;module&#39; => &#39;vote&#39;, &#39;action&#39; => &#39;new&#39;),
(&#39;sf_method&#39; => (&#39;get&#39;))
      ),
      &#39;vote_create&#39; =>  sfRequestRoute(
        &#39;/vote/create&#39;,
(&#39;module&#39; => &#39;vote&#39;, &#39;action&#39; => &#39;create&#39;),
(&#39;sf_method&#39; => (&#39;post&#39;))
      ),
      &#39;vote_edit&#39; =>  sfDoctrineRoute(
        &#39;/vote/edit/:id&#39;,            (&#39;module&#39; => &#39;vote&#39;, &#39;action&#39; => &#39;edit&#39;),
(&#39;id&#39; => &#39;\d+&#39;, &#39;sf_method&#39; => (&#39;get&#39;)),
(&#39;model&#39; => &#39;VoteQuestion&#39;, &#39;type&#39; => &#39;object&#39;)
      ),
      &#39;vote_update&#39; =>  sfDoctrineRoute(
        &#39;/vote/update/:id&#39;,
(&#39;module&#39; => &#39;vote&#39;, &#39;action&#39; => &#39;update&#39;),
(&#39;id&#39; => &#39;\d+&#39;, &#39;sf_method&#39; => (&#39;post&#39;)),
(&#39;model&#39; => &#39;VoteQuestion&#39;, &#39;type&#39; => &#39;object&#39;)
      ),
      &#39;vote_show&#39; =>  sfDoctrineRoute(
        &#39;/vote/show/:id&#39;,
(&#39;module&#39; => &#39;vote&#39;, &#39;action&#39; => &#39;show&#39;),
(&#39;id&#39; => &#39;\d+&#39;, &#39;sf_method&#39; => (&#39;get&#39;)),
(&#39;model&#39; => &#39;VoteQuestion&#39;, &#39;type&#39; => &#39;object&#39;)
      ),
      &#39;vote_post&#39; =>  sfDoctrineRoute(
        &#39;/vote/post/:id&#39;,
(&#39;module&#39; => &#39;vote&#39;, &#39;action&#39; => &#39;post&#39;),
(&#39;id&#39; => &#39;\d+&#39;, &#39;sf_method&#39; => (&#39;post&#39;)),
(&#39;model&#39; => &#39;VoteQuestion&#39;, &#39;type&#39; => &#39;object&#39;)
      ),
      &#39;vote_delete_confirm&#39; =>  sfDoctrineRoute(
        &#39;/vote/delete/:id&#39;,
(&#39;module&#39; => &#39;vote&#39;, &#39;action&#39; => &#39;deleteConfirm&#39;),
(&#39;id&#39; => &#39;\d+&#39;, &#39;sf_method&#39; => (&#39;get&#39;)),
(&#39;model&#39; => &#39;VoteQuestion&#39;, &#39;type&#39; => &#39;object&#39;)
      ),
      &#39;vote_delete&#39; =>  sfDoctrineRoute(
        &#39;/vote/delete/:id&#39;,
(&#39;module&#39; => &#39;vote&#39;, &#39;action&#39; => &#39;delete&#39;),
(&#39;id&#39; => &#39;\d+&#39;, &#39;sf_method&#39; => (&#39;post&#39;)),
(&#39;model&#39; => &#39;VoteQuestion&#39;, &#39;type&#39; => &#39;object&#39;)
      ),
     &#39;vote_nodefaults&#39; =>  sfRoute(
        &#39;/vote/*&#39;,
(&#39;module&#39; => &#39;default&#39;, &#39;action&#39; => &#39;error&#39;)
      ),
    );
  }
}
?>

创建plugins/opVotePlugin/apps/pc_frontend/config/routing.yml

输入

vote:
: opVotePluginFrontendRouteCollection
  options: { name: vote }

指定由哪个类来设定路由规则

输入命令php symfony cc

输入命令php symfony app:routes pc_frontend 查看路由是否设定成功

不创建opVotePluginFrontendCollection..php与routing.yml文件也可,将按默认路由访问

推荐学习:php视频教程

Atas ialah kandungan terperinci 用openPNE怎样才能创建一个项目. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Artikel ini dikembalikan pada:cnblogs.com. Jika ada pelanggaran, sila hubungi admin@php.cn Padam