hussfelt / zend-model-creator-2
此项目旨在避免在 ZendFramework 项目中创建实体/服务/映射器所花费的时间。它基于 ZF-Commons 团队的一些部分。
Requires
- php: >=5.3.3
Suggests
- zendframework/zendframework: 2.*
- zf-commons/zfc-base: dev-master
This package is not auto-updated.
Last update: 2024-09-22 03:24:05 UTC
README
版本 0.0.1 由 Henrik Hussfelt 创建
简介
Zend Model Creator 是一个用于快速原型设计您的 Zend 项目的生成器。如果您不热衷于使用纯 ORM(如 Doctrine),这可能适合您。
默认情况下,Zend Model Creator 与 Zend\Db 一起工作,并根据您的数据库结构生成实体、映射器和事件感知服务。
此项目主要用于避免在您的 Zend Framework 项目中创建模型所花费的时间。
要求
- PHP5
- Zend Framework 2 - 生成模型不需要
- ZfcBase - 生成模型不需要
功能/目标
- 生成实体 [完成]
- 生成映射器 [完成]
- 生成事件感知服务 [完成]
- 生成事件服务 [完成]
- 生成 Module.php [完成]
- 生成自动加载文件 [完成]
- 生成添加表单 [未完成]
- 生成编辑表单 [未完成]
- 生成表单过滤器 [未完成]
安装
通过 git 安装
克隆此存储库 git clone git@github.com:hussfelt/Zend-Model-Creator-2.git
进入您的目录 cd Zend-Model-Creator-2
通过 Composer 安装
将此添加到您的 composer.json 中 "require" 部分:"hussfelt/zend-model-creator-2": "dev-master"
运行命令:php composer.phar update
使用
进入目录(使用 composer 安装):cd vendor/hussfelt/zend-model-creator-2
使用 php 运行:php zmc.php --host=[DB_HOST] --db=[DATABASE_NAME] --user=[USERNAME] --password=[PASSWORD]
- 将您的 [NAMESPACE] 目录移动到 /vendor/ 目录
- 将 [NAMESPACE] 添加到您的 application.config.php
return array( 'modules' => array( 'ZfcBase', '[NAMESPACE_HERE]', 'Application', ), );
选项
--without-entity=1
将不会生成实体
--without-mapper=1
将不会生成映射器
--without-service=1
将不会生成服务
--without-module=1
将不会生成 Module.php 文件
--without-autoloaders=1
将不会生成自动加载文件
--without-config=1
将不会生成配置文件
--without-options=1
将不会生成选项文件
--namespace=[NAMESPACE]
将在给定的命名空间中生成数据,而不是使用 ZMC2
在控制器中的示例用法
这将替换 Zend Framework Skeleton 应用程序 中的 IndexController.php。假设您数据库中有一个名为 "album" 的数据库表,这将输出该表中的所有 "名称" 记录。
module/Application/src/Application/Controller/IndexController.php
<?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Application\Controller; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; class IndexController extends AbstractActionController { protected $albumService; protected $options; public function indexAction() { // Get all albums from service $albums = $this->getAlbumService()->findAll(); foreach ($albums as $album) { echo $album->getName() . "<br />"; } exit; } public function getAlbumService() { if (!isset($this->albumService)) { $this->albumService = $this->getServiceLocator()->get('ZmcBase\Service\Album'); } return $this->albumService; } }
另外,如果您还没有这样做,您需要修复您的 global.php 和 local.php 配置文件。
config/autoload/global.php
<?php /** * Global Configuration Override * * You can use this file for overridding configuration values from modules, etc. * You would place values in here that are agnostic to the environment and not * sensitive to security. * * @NOTE: In practice, this file will typically be INCLUDED in your source * control, so do not include passwords or other sensitive information in this * file. */ return array( 'db' => array( 'driver' => 'Pdo', 'dsn' => 'mysql:dbname=[YOUR_DATABASE_NAME];host=[YOUR_DB_HOST]', 'driver_options' => array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' ), ), 'service_manager' => array( 'factories' => array( 'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory', ), ), );
config/autoload/local.php
<?php /** * Local Configuration Override * * This configuration override file is for overriding environment-specific and * security-sensitive configuration information. Copy this file without the * .dist extension at the end and populate values as needed. * * @NOTE: This file is ignored from Git by default with the .gitignore included * in ZendSkeletonApplication. This is a good practice, as it prevents sensitive * credentials from accidentally being comitted into version control. */ return array( 'db' => array( 'username' => '[DB_USERNAME]', 'password' => '[DB_PASSWORD]', ), );