Upgrade to Pro — share decks privately, control downloads, hide ads and more …

App Development with ZF2 - A real world problem example

App Development with ZF2 - A real world problem example

Talk for BEPHPUG about app development with Zend Framework 2.

https://github.com/wesrc/secretary is used as example, to demonstrate, how a ZF2 MVC App could look like.

Michael Scholl

March 05, 2013
Tweet

More Decks by Michael Scholl

Other Decks in Technology

Transcript

  1. hu? ZF2 MVC ZF2 Modules ZF2 EventManager ZF2 + Doctrine

    … no live coding! but a real world problem solution…
  2. of course… YOU have no problem, because you always send

    credentials by FAX to your peers & customers! or YOU are the person who is having great fun, telling your customers credentials on the phone and using passwords like this: „B3y3^zA#](}7j6#tmJ=[r“
  3. me don‘t like using phone at all! (FAX¿ - don‘t

    get me started about FAX PlugIns for my „digital workstation“)
  4. let‘s do that with ZF2 of course, we use Composer

    ! (and ZF community fortunately decided to do so, too) cd ~/Sites/zf2test git clone git://github.com/zendframework/ ZendSkeletonApplication.git cd ZendSkeletonApplication php composer.phar install or php composer.phar create-project --repository-url="http:// packages.zendframework.com" zendframework/skeleton- application ~/Sites/zf2test
  5. APPLICATION.CONFIG.PHP modules: a list of modules you want to use

    module_listener_options: where to find your modules & how to load other config files by pattern
  6. ZF2 Modules can be pretty anything ([more or less] code,

    assets, configs) there is no structure you have to follow but there is a structure, you could/should follow you need a Module.php in the module root Module.php needs its own Namespace
  7. Module Folder Structure modules Namespace config language public css js

    images src Namespace Controller Form Service ... test view layout namespace
  8. ZF2 ModuleManager „A flexible and powerful system for loading managing

    modules“ (Evan Coury) Loads all your modules and fires some listeners AutoloaderListener ConfigListener InitTrigger OnBootstrapListener LocatorRegistrationListener ServiceListener Makes use of ZF2 EventManager
  9. ZF2 Modules more background info: http://www.zend.com/en/resources/webinars/framework?#ZF2ModMan (Webinar with Evan Coury)

    http://blog.evan.pro/introduction-to-modules-in-zend-framework-2-talk- at-zendcon-2012 http://evan.pro/slides/Introduction-to-Modules-in-Zend-Framework-2- ZendCon-2012.html#slide1 http://akrabat.com/zend-framework-2/modules-in-zf2/
  10. ZF2 ServiceManager because we can write $sm then! because everybody

    right now uses a DIC your module.config.php will feed the ServiceManager and get you up and running I assume, you already understand the concepts behind DIC (Dependency Injection Container) and IoC (Inversion of Control), if not…
  11. ZF2 ServiceManager Background Info: http://blog.astrumfutura.com/2011/10/zend-framework-2-0- dependency-injection-part-1/ - http://blog.astrumfutura.com/2011/10/ zend-framework-2-0-dependency-injection-part-2/ (must

    read!) http://www.maltblue.com/articles-2/zend-framework-2-core-concepts- understanding-dependency-injection http://www.maltblue.com/tutorial/zend-framework-2-servicemanager http://ralphschindler.com/2012/10/10/di-dic-service-locator-redux http://akrabat.com/zend-framework-2/zendservicemanager- configuration-keys/ (helpful doc article!) http://juriansluiman.nl/en/article/120/using-zend-framework-service- managers-in-your-application (great article!)
  12. ZF2 EventManager ZF2 MVC makes heavy usage of EventManager Everything

    is bound to an event If you want to hook into any bootstrapping process, you will end in attaching to an event You can use the EventManager to integrate event based logic into your own app
  13. MODULE.PHP - INIT LOGGER ONLY GIVEN IDENTIFIER CAN TRIGGER EVENTS

    ! (USE * WILDCARD INSTEAD, IF NEEDED EVERYWHERE)
  14. MODULE.PHP - VIEW CONFIG SET ACL FOR NAVIGATION VIEW PLUGIN

    ENABLE MARKDOWN VIEW PLUGIN will be callable by $this->SecretaryMarkdown($foo) in view
  15. MODULE.PHP - FORM CONFIG THIS ONE IS LITTLE BIT CRAZY

    IF YOU WANT TO USE DoctrineORMModule\Form\Element\EntitySelect
  16. KEYCONTROLLER.PHP - PRESDISPATCH & INDEX PREDISPATCH IS A OWN EVENT!

    (that is created in MvcController) add key-de_DE.mo and key-us_US.mo to translator Check, if key is already created. If not, create KeyForm. Return keyRecord and keyForm as ViewModel Attributes
  17. KEYCONTROLLER.PHP - ADD ACTION If Request is POST Create new

    KeyRecord and get Input Filter out of it. Fill Form with POST data If form is valid Get passphrase out of form values Generate Private Key Save Public Key for User ($this->identity) Add Private Key to ViewModel Update User Role
  18. ZF2 - More Infos http://framework.zend.com/manual/2.1/en/index.html http://www.zend.com/en/resources/webinars/framework http://akrabat.com/ http://blog.astrumfutura.com/ http://blog.evan.pro http://www.mwop.net

    http://ralphschindler.com http://www.zimuel.it/en/ ZF MailingList: http://framework.zend.com/wiki/display/ZFDEV/Mailing+Lists GITHUB: https://github.com/zendframework/zf2 IRC: http://www.zftalk.com/channel/