SlideShare uma empresa Scribd logo
1 de 40
ZF2 For ZF1 Developers
        Gary Hockin
     5th December 2012
     26th February 2013
Who?
http://blog.hock.in
          @GeeH
Spabby in #zftalk (freenode)
What?
Why?
THERE WILL BE CODE!
Getting Started
Namespaces
ZF1
class FeaturedController extends Zend_Controller_Action
{
    public function indexAction ()
    {
        $logfile = date('dmY') . '.log';
        $logger = new Zend_Log();
        $writer = new Zend_Log_Writer_Stream ($logfile);
        $logger->addWriter( $writer);
    }
}
ZF2
namespace ApplicationController;

use ZendMvcControllerAbstractActionController;
use ZendLogLogger;
use ZendLogWriterStream as Writer;

class FeaturedController extends AbstractActionController;
{
    public function indexAction ()
    {
        $logfile = date('dmY') . '.log';
        $logger = new Logger();
        $writer = new Writer($logfile);
        $logger->addWriter( $writer);
    }
}
Goodbye...

Long_Underscore_Seperated_Class


           Hello...

 NiceSnappyNamespacedClass
Modules
Bootstrapping
Service Manager
namespace Application;

use ZendMvcControllerAbstractActionController;
use ApplicationServiceMyService;

class MyController extends AbstractActionController
{
    protected $myService;

    public function __construct (MyService $myService)
    {
        $this->myService = $myService;
    }

    public function indexAction ()
    {
        return array(
            'myViewVar' => $myService->getMyViewVar()
        );
    }
}
use ApplicationControllerMyController;

public function getServiceConfig ()
{
    return array(
        'factories' => array(
            'myService' => function( ServiceManager $sm) {
                $myService = new ApplicationService MyService();
                $myService->setSomeProperty( true);
                return $myService;
            },
        ),
    );
}

public function getControllerConfig ()
{
    return array(
        'factories' => array(
            'MyController' => function( ServiceLocator $sl) {
                  $myService = $sl->getServiceManager() ->get('myService' );
                  $myController = new MyController ($myService);
                 return $myService;
             },
        ),
    );
}
Dependency Injector
Event Manager
Module.php
public function init(ModuleManager $moduleManager)
{
    $moduleManager->getEventManager() ->attach(
        'loadModules.pre' ,
        function(ZendModuleManager ModuleEvent $e) {
            // do some pre module loading code here
        }
    );
}
Module.php
public function onBootstrap (ModuleManager $moduleManager)
{
    $moduleManager->getEventManager() ->attach(
        'myUser.Logout' ,
        function(ZendModuleManager ModuleEvent $e) {
            // cleanup some cache/temp files here
        }
    );
}

/**
 * MyService class
 * Presume you have passed the EM into $eventManager via SM or Di
 **/
public function logout()
{
      do Logout code
     $this->eventManager ->trigger('myUser.Logout' );
}
Routing
ZF1
;Match route /product/1289 to ProductController DetailsAction with the
parameter ProductId set to 1289

resources.router.routes.product.route = "/product/:ProductId"
resources.router.routes.product.defaults.controller = "product"
resources.router.routes.product.defaults.action = "details"
ZF2
return array(
    'router' => array(
        'routes' => array(
            'category' => array(
                'type' => 'Segment',
                'options' => array(
                    'route' => '/product/:ProductId' ,
                    'constraints' => array(
                        'ProductId' => '[0-9]*'
                    ),
                    'defaults' => array(
                        '__NAMESPACE__' => 'ApplicationController' ,
                        'controller' => 'Product',
                        'action' => 'details',
                    ),
                ),
            ),
            ...
Zend View
Zend View
View Helpers
ZF1
application.ini

 resources.view.helperPath.My_View_Helper   = "My/View/Helper"

My/View/Helper/Bacon.php

 class My_View_Helper_Bacon extends Zend_View_Helper_Abstract
 {
     public function bacon()
     {
         return 'Bacon';
     }
 }
ZF2
Module.php

 public function getViewHelperConfig ()
 {
     return array(
         'invokables' => array(
             'bacon' => 'MyViewHelperBacon'
         )
     );
 }

MyViewHelperBacon.php

 namespace MyViewHelper

 class Bacon extends  ZendViewHelperAbstractHelper
 {
     public function __invoke()
     {
         return 'bacon';
     }
 }
Zend Db
Zend Db Adapter
          &
Zend Db TableGateway
ZF1
application.ini
 resources.db.adapter = "PDO_MYSQL"
 resources.db.isdefaulttableadapter = true
 resources.db.params.dbname = "mydb"
 resources.db.params.username = "root"
 resources.db.params.password = "password"
 resources.db.params.host = "localhost"



ApplicationModelTableUser.php

 class Application_Model_Table_User extends Zend_Db_Table_Abstract
 {
     protected $_name = 'user';

     public function getUser($id)
     {
         return $this->find($id);
     }
 }
ZF2
configautoloaddatabase.local.php
 return array(
     'service_manager' => array(
         'factories' => array(
             'Adapter' => function ( $sm) {
                 return new ZendDbAdapter Adapter(array(
                     'driver'    => 'pdo',
                     'dsn'       => 'mysql:dbname=db;host=127.0.0.1' ,
                     'database' => 'db',
                     'username' => 'user',
                     'password' => 'bacon',
                     'hostname' => '127.0.0.1' ,
                 ));
             },
         ),
     ),
 );
ZF2
ApplicationModule.php
 namespace Application;
 use ZendDbTableGatewayTableGateway;

 class Module
 {
     public function getServiceConfig ()
     {
         return array(
              'factories' => array(
                  'UserTable' => function ( $serviceManager) {
                      $adapter = $serviceManager->get('Adapter');
                      return new TableGateway ('user', $adapter);
                  },
             ),
         );
     }
ZF2
ApplicationControllerIndexController.php
 namespace ApplicationController;

 class IndexController extends AbstractActionController
 {
     public function indexAction ()
     {
         $userTable = $this->getServiceLocator() ->get('UserTable' );
         return new ViewModel(array('user' => $userTable->select(
             array('id' => '12345'))
         ));
     }
 }
Zend Db TableGateway
          &
  Object Hydration
Zend Db TableGateway
          &
  Object Hydration

    http://hock.in/WIP1qa
Zend Form
Zend Form
http://hock.in/11SCIvU
Questions?

     http://blog.hock.in
           @GeeH
 Spabby in #zftalk (freenode)


       Slides and Feedback:

https://joind.in/8247
ZF2 for the ZF1 Developer

Mais conteúdo relacionado

Mais procurados

Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
Fabien Potencier
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
Compare Infobase Limited
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
Fabien Potencier
 

Mais procurados (20)

Moodle 3.3 - API Change Overview #mootieuk17
Moodle 3.3 - API Change Overview #mootieuk17Moodle 3.3 - API Change Overview #mootieuk17
Moodle 3.3 - API Change Overview #mootieuk17
 
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
Zf2 phpquebec
Zf2 phpquebecZf2 phpquebec
Zf2 phpquebec
 
PHP MVC
PHP MVCPHP MVC
PHP MVC
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용
 
Drupal 8 Services
Drupal 8 ServicesDrupal 8 Services
Drupal 8 Services
 
An Introduction to Drupal
An Introduction to DrupalAn Introduction to Drupal
An Introduction to Drupal
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
 
Writing Drupal 5 Module
Writing Drupal 5 ModuleWriting Drupal 5 Module
Writing Drupal 5 Module
 
Presentation
PresentationPresentation
Presentation
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
 
The Beauty and the Beast
The Beauty and the BeastThe Beauty and the Beast
The Beauty and the Beast
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
 
Require js and Magento2
Require js and Magento2Require js and Magento2
Require js and Magento2
 
OSGi framework overview
OSGi framework overviewOSGi framework overview
OSGi framework overview
 

Semelhante a ZF2 for the ZF1 Developer

ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf Conference
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
D
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency Injection
Anton Kril
 

Semelhante a ZF2 for the ZF1 Developer (20)

Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic Components
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web services
 
Zend framework service
Zend framework serviceZend framework service
Zend framework service
 
Zend framework service
Zend framework serviceZend framework service
Zend framework service
 
Migrating to dependency injection
Migrating to dependency injectionMigrating to dependency injection
Migrating to dependency injection
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Into the ZF2 Service Manager
Into the ZF2 Service ManagerInto the ZF2 Service Manager
Into the ZF2 Service Manager
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar Simović"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar Simović
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency Injection
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

ZF2 for the ZF1 Developer

  • 1. ZF2 For ZF1 Developers Gary Hockin 5th December 2012 26th February 2013
  • 3.
  • 4. http://blog.hock.in @GeeH Spabby in #zftalk (freenode)
  • 10. ZF1 class FeaturedController extends Zend_Controller_Action { public function indexAction () { $logfile = date('dmY') . '.log'; $logger = new Zend_Log(); $writer = new Zend_Log_Writer_Stream ($logfile); $logger->addWriter( $writer); } }
  • 11. ZF2 namespace ApplicationController; use ZendMvcControllerAbstractActionController; use ZendLogLogger; use ZendLogWriterStream as Writer; class FeaturedController extends AbstractActionController; { public function indexAction () { $logfile = date('dmY') . '.log'; $logger = new Logger(); $writer = new Writer($logfile); $logger->addWriter( $writer); } }
  • 12. Goodbye... Long_Underscore_Seperated_Class Hello... NiceSnappyNamespacedClass
  • 16. namespace Application; use ZendMvcControllerAbstractActionController; use ApplicationServiceMyService; class MyController extends AbstractActionController { protected $myService; public function __construct (MyService $myService) { $this->myService = $myService; } public function indexAction () { return array( 'myViewVar' => $myService->getMyViewVar() ); } }
  • 17. use ApplicationControllerMyController; public function getServiceConfig () { return array( 'factories' => array( 'myService' => function( ServiceManager $sm) { $myService = new ApplicationService MyService(); $myService->setSomeProperty( true); return $myService; }, ), ); } public function getControllerConfig () { return array( 'factories' => array( 'MyController' => function( ServiceLocator $sl) { $myService = $sl->getServiceManager() ->get('myService' ); $myController = new MyController ($myService); return $myService; }, ), ); }
  • 20. Module.php public function init(ModuleManager $moduleManager) { $moduleManager->getEventManager() ->attach( 'loadModules.pre' , function(ZendModuleManager ModuleEvent $e) { // do some pre module loading code here } ); }
  • 21. Module.php public function onBootstrap (ModuleManager $moduleManager) { $moduleManager->getEventManager() ->attach( 'myUser.Logout' , function(ZendModuleManager ModuleEvent $e) { // cleanup some cache/temp files here } ); } /** * MyService class * Presume you have passed the EM into $eventManager via SM or Di **/ public function logout() { do Logout code $this->eventManager ->trigger('myUser.Logout' ); }
  • 23. ZF1 ;Match route /product/1289 to ProductController DetailsAction with the parameter ProductId set to 1289 resources.router.routes.product.route = "/product/:ProductId" resources.router.routes.product.defaults.controller = "product" resources.router.routes.product.defaults.action = "details"
  • 24. ZF2 return array( 'router' => array( 'routes' => array( 'category' => array( 'type' => 'Segment', 'options' => array( 'route' => '/product/:ProductId' , 'constraints' => array( 'ProductId' => '[0-9]*' ), 'defaults' => array( '__NAMESPACE__' => 'ApplicationController' , 'controller' => 'Product', 'action' => 'details', ), ), ), ...
  • 27. ZF1 application.ini resources.view.helperPath.My_View_Helper = "My/View/Helper" My/View/Helper/Bacon.php class My_View_Helper_Bacon extends Zend_View_Helper_Abstract { public function bacon() { return 'Bacon'; } }
  • 28. ZF2 Module.php public function getViewHelperConfig () { return array( 'invokables' => array( 'bacon' => 'MyViewHelperBacon' ) ); } MyViewHelperBacon.php namespace MyViewHelper class Bacon extends ZendViewHelperAbstractHelper { public function __invoke() { return 'bacon'; } }
  • 30. Zend Db Adapter & Zend Db TableGateway
  • 31. ZF1 application.ini resources.db.adapter = "PDO_MYSQL" resources.db.isdefaulttableadapter = true resources.db.params.dbname = "mydb" resources.db.params.username = "root" resources.db.params.password = "password" resources.db.params.host = "localhost" ApplicationModelTableUser.php class Application_Model_Table_User extends Zend_Db_Table_Abstract { protected $_name = 'user'; public function getUser($id) { return $this->find($id); } }
  • 32. ZF2 configautoloaddatabase.local.php return array( 'service_manager' => array( 'factories' => array( 'Adapter' => function ( $sm) { return new ZendDbAdapter Adapter(array( 'driver' => 'pdo', 'dsn' => 'mysql:dbname=db;host=127.0.0.1' , 'database' => 'db', 'username' => 'user', 'password' => 'bacon', 'hostname' => '127.0.0.1' , )); }, ), ), );
  • 33. ZF2 ApplicationModule.php namespace Application; use ZendDbTableGatewayTableGateway; class Module { public function getServiceConfig () { return array( 'factories' => array( 'UserTable' => function ( $serviceManager) { $adapter = $serviceManager->get('Adapter'); return new TableGateway ('user', $adapter); }, ), ); }
  • 34. ZF2 ApplicationControllerIndexController.php namespace ApplicationController; class IndexController extends AbstractActionController { public function indexAction () { $userTable = $this->getServiceLocator() ->get('UserTable' ); return new ViewModel(array('user' => $userTable->select( array('id' => '12345')) )); } }
  • 35. Zend Db TableGateway & Object Hydration
  • 36. Zend Db TableGateway & Object Hydration http://hock.in/WIP1qa
  • 39. Questions? http://blog.hock.in @GeeH Spabby in #zftalk (freenode) Slides and Feedback: https://joind.in/8247