SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

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 #mootieuk17Dan Poltawski
 
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework Matteo Magni
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용Sungchul Park
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with ExpressAaron Stannard
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownpartsBastian Feder
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Fabien Potencier
 
Writing Drupal 5 Module
Writing Drupal 5 ModuleWriting Drupal 5 Module
Writing Drupal 5 ModuleSammy Fung
 
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
 
The Beauty and the Beast
The Beauty and the BeastThe Beauty and the Beast
The Beauty and the BeastBastian Feder
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data ObjectsWez Furlong
 
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.4Fabien Potencier
 
Require js and Magento2
Require js and Magento2Require js and Magento2
Require js and Magento2Irene Iaccio
 
OSGi framework overview
OSGi framework overviewOSGi framework overview
OSGi framework overviewBalduran Chang
 

Tendances (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
 

Similaire à ZF2 for the ZF1 Developer

Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic ComponentsMateusz Tymek
 
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
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologyDaniel Knell
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web servicesMichelangelo van Dam
 
Migrating to dependency injection
Migrating to dependency injectionMigrating to dependency injection
Migrating to dependency injectionJosh Adell
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
 
Into the ZF2 Service Manager
Into the ZF2 Service ManagerInto the ZF2 Service Manager
Into the ZF2 Service ManagerChris Tankersley
 
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 DevelopmentNuvole
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
"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ćJS Belgrade
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ EtsyNishan Subedi
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Shinya Ohyanagi
 
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 2012D
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency InjectionAnton Kril
 

Similaire à 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
 

Dernier

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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...Miguel Araújo
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Dernier (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

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