快速创建一个zend framework 2的module
来源:互联网 发布:屏蔽ip地址软件 编辑:程序博客网 时间:2024/06/06 12:29
资源 ZendSkeletonModule: https://github.com/zendframework/ZendSkeletonModule。
首先假定,已经部署好了zend framework 2项目框架。如果没有,参见前面的文章从零创建zend framework 2项目框架。
目录也参见上一个项目的目录:/var/www/newzf2
将ZendSkeletonModule解压到/var/www/newzf2/module/下新增了一个目录/var/web/newzf2/module/ZendSkeletonModule-master
将ZendSkeletonModule-master改名为Register。
进入/var/web/newzf2/module/Register,
目录内容如下:
autoload_classmap.phpautoload_function.phpautoload_register.phpconfigLICENSE.txtModule.phpREADME.mdsrctestsview
将Module.php内容的namespace ZendSkeletonModule;改为namespace Users;
controller的修改
将/var/web/newzf2/module/Register/src/ZendSkeletonModule/Controller/SkeletonController.php 改为
/var/web/newzf2/module/Register/src/Register/Controller/IndexController.php
文件内容:
将IndexController.php的namespace ZendSkeletonModule\Controller; 改为namespace Register\Controller;
class SkeletonController 改为class IndexController
namespace Register\Controller;use Zend\Mvc\Controller\AbstractActionController;class IndexController extends AbstractActionController{ public function indexAction() { return array(); } public function fooAction() { // This shows the :controller and :action parameters in default route // are working when you browse to /module-specific-root/skeleton/foo return array(); }}
view的修改
将/var/web/newzf2/module/Register/view/zend-skeleton-module/skeleton/改为
/var/web/newzf2/module/Register/view/register/index/
module 配置文件:
cd /var/web/newzf2/module/Register
1. autoload配置文件。
修改autoload_classmap.php的内容,用一下内容替换:
<?phpreturn array();
2.module配置信息
module的配置文件位置:config/module.config.php;
默认内容如下:
<?phpreturn array( 'controllers' => array( 'invokables' => array( 'ZendSkeletonModule\Controller\Skeleton' => 'ZendSkeletonModule\Controller\SkeletonController', ), ), 'router' => array( 'routes' => array( 'module-name-here' => array( 'type' => 'Literal', 'options' => array( // Change this to something specific to your module 'route' => '/module-specific-root', 'defaults' => array( // Change this value to reflect the namespace in which // the controllers for your module are found '__NAMESPACE__' => 'ZendSkeletonModule\Controller', 'controller' => 'Skeleton', 'action' => 'index', ), ), 'may_terminate' => true, 'child_routes' => array( // This route is a sane default when developing a module; // as you solidify the routes for your module, however, // you may want to remove it and replace it with more // specific routes. 'default' => array( 'type' => 'Segment', 'options' => array( 'route' => '/[:controller[/:action]]', 'constraints' => array( 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', ), 'defaults' => array( ), ), ), ), ), ), ), 'view_manager' => array( 'template_path_stack' => array( 'ZendSkeletonModule' => __DIR__ . '/../view', ), ),);
修为动作:
controller改为:
'controllers' => array( 'invokables' => array( 'Register\Controller\Index' => 'Register\Controller\IndexController', ), ),view修改:
'view_manager' => array( 'template_path_stack' => array( 'register' => __DIR__ . '/../view', ), ),注意,view使用小写字母,多个词语的module使用“-”横划线连接。例如:ZendSkeleton要写成 zend-skeleton。
Routes的配置:(三处需要修改)
'module-name-here' => array(
'route' => '/module-specific-root',
'__NAMESPACE__' => 'ZendSkeletonModule\Controller',
'controller' => 'Skeleton',
'action' => 'index',
'controller' => 'Skeleton',
'action' => 'index',
'router' => array( 'routes' => array( 'module-name-here' => array( 'type' => 'Literal', 'options' => array( // Change this to something specific to your module 'route' => '/module-specific-root', 'defaults' => array( // Change this value to reflect the namespace in which // the controllers for your module are found '__NAMESPACE__' => 'ZendSkeletonModule\Controller', 'controller' => 'Skeleton', 'action' => 'index', ), ), 'may_terminate' => true, 'child_routes' => array( // This route is a sane default when developing a module; // as you solidify the routes for your module, however, // you may want to remove it and replace it with more // specific routes. 'default' => array( 'type' => 'Segment', 'options' => array( 'route' => '/[:controller[/:action]]', 'constraints' => array( 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', ), 'defaults' => array( ), ), ), ), ), ), ),
添加Application 配置文件
cd /var/web/newzf2/config,修改application.config.php
添加register module配置:
'modules' => array( 'Application', 'Register', ),
为了调试方便,最好打开错误日志。
一种是在public/index.php
error_reporting(E_ALL);
ini_set("display_errors", 1);
ini_set("display_errors", 1);
一种是修改php.ini
error_reporting = E_ALL & ~E_STRICT,
打开短标签支持,方便ZF2模板编写:
short_open_tag = On
short_open_tag = On
访问:http://host/register; http://host/register/index/index; http://host/register/index/foo 都正确显示。
0 0
- 快速创建一个zend framework 2的module
- Zend Framework教程-用Zend命令行快速创建Zend应用
- Zend Framework 2 Module.php 简要说明
- Zend Framework 1.10.1 快速入门之三: 创建一个布局
- Zend Framework 1.10.1 快速入门之四:创建一个模型和数据库表格
- Zend Framework 1.10.1 快速入门之五:创建一个表单
- 使用ZFTool创建全新的zend framework 2项目
- Zend Framework教程2-创建你的项目
- Zend Framework 1.10.1 快速入门之二:创建 Zend Framework 项目
- Zend Framework 快速开始
- Zend Framework 2 module.config.php配置详解
- Zend Framework 2 : Move out your listeners from Module class
- Zend Framework模块创建
- Zend framework创建
- 创建Zend Framework 项目
- Zend framework acl的一个实例.
- Create RESTful Applications Using The Zend Framework(使用Zend Framework创建一个Restful应用)
- zend framework quickstart zend框架入门之创建工程(快速开始:一)
- wordpress模板文件及其常用函数
- JavaScript数组遍历
- oracle常见问题汇总
- php提示Call to undefined function curl_init() 错误的解决办法
- 配置GoogleMap后android.view.InflateException:Binary XML file line # 10:Error inflating class
- 快速创建一个zend framework 2的module
- input链接页面
- .NET的Snk使用方法
- 回收站清空文件要如何进行恢复
- .net截屏代码
- 收集的一些资源列表包括小工具源码等
- Windows 图形界面笔记(1) - 窗口的显示
- ueditor有的机器显示有的机器页面空白--解决
- Win 2008 R2安装SQL Server 2008“性能计数器注册表配置单元一致性”失败的解决办法 性能计数器注册表配置单位元一致性 失败 300956