Show Menu
Cheatography

Projeto Zend Framework 2 + Doctrine 2 Cheat Sheet by

Comandos de console em composer, zftool e doctrine tool

Criação e instalação

$ zftool.phar create project nome
$ cd nome
$ composer install
$ composer require zendframework/zftool:dev-master
$ composer require doctrine/doctrine-orm-module:0.7.*
$ composer require zendframework/zend-developer-tools:dev-master
$ cp vendor/framework/zend-developer-tools/config/zenddevelopertools.local.php.dist config/autoload/ztd.local.php
$ composer require hounddog/doctrine-data-fixture-module:dev-master
1 - Criação do projeto Zend Framework
2 - Vá para o diretório do projeto
3 - Instalação dos arquivos do ZF2
4 - Instalação do ZFTools para o projeto.
5 - Instalação do Doctrine 2
6 - Instalação do Zend Developer Tools
7 - Copiando o config do ZDT para o projeto.
8 - Instalando modulo de data fixture

Doctrine - comandos

Validar
$ vendor­/bi­n/d­oct­rin­e-m­odule orm:va­lid­ate­-schema
Criar
$ vendor­/bi­n/d­oct­rin­e-m­odule orm:sc­hem­a-t­ool­:create
Atualizar
$ vendor­/bi­n/d­oct­rin­e-m­odule orm:sc­hem­a-t­ool­:update
Drop
$ vendor­/bi­n/d­oct­rin­e-m­odule orm:sc­hem­a-t­ool­:drop
Veri­ficar pronto para subir (Produ­ction enviro­ment)
$ vendor­/bi­n/d­oct­rin­e-m­odule orm:en­sur­e-p­rod­uct­ion­-se­ttings
Criar Entinty
$ vendor/bin/doctrine-module orm:generate-entities
Opcionais: --upda­te-­ent­ities ou --rege­ner­ate­-en­tities

Zend Framework Tool - Comandos

Controller
$ zftool.phar create controller nome Application
Action
$ zftool.phar create action nome Controller Application
O comando de criação de action destrói a indentação do arquivo.

Link

 

Config­urações

config/application.config.php
'modules' => array(
        'ZendDeveloperTools',
        'DoctrineModule',
        'DoctrineORMModule',
        'Application',
    ),

module/Application/config/module.config.php
'doctrine' => array(
        'driver' => array(
            'application_entities' => array(
                'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../src/Application/Entity')
                ),
        'orm_default' => array(
            'drivers' => array('Application\Entity' => 'application_entities')
            )
        )
    )

config/autoload/doctrine.local.php
return array(
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' =>'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'user' => 'usuario',
'password' => 'senha',
'dbname' => 'database'
)))));
Adicionar os modulos ZendDe­vel­ope­rTools (Para depura­ção), Doctri­neM­odule e Doctri­neO­RMM­odule.

Tweak no Route

Para o module Application funcionar como base
'application' => array(
                'type' => 'Segment',
                'options' => array(
                    'route' => '[]',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller' => 'Index',
                        'action' => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    '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(
                            ),
                        ),
                    ),
                ),
            ),
type: Literal Segment
route: "­/ap­pli­cat­ion­" "­[]"
           

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          PHP Cheat Sheet
          PHP Cheat Sheet
          PHP-FIG PSR Standards Cheat Sheet