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

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
 

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

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
 

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

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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...Neo4j
 
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 WorkerThousandEyes
 
🐬 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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
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 productivityPrincipled Technologies
 
[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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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...
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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...
 
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
 
[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
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

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