26
Zend Framework 2 http://slidesha.re/134YKwL

Zend Framework 2 - presentation

  • Upload
    yamcsha

  • View
    1.207

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Zend Framework 2 - presentation

Zend Framework 2

http://slidesha.re/134YKwL

Page 2: Zend Framework 2 - presentation

Prerequisites

Page 3: Zend Framework 2 - presentation

Standards:

- PHP 5.3.3+ (with pdo-sqlite or pdo-mysql)- Translation: php5-intl

Optional:- composer (easy install/update modules)- Git

- PSR 0 (autoloader interoperability)- PSR 1 & 2 (Coding Standard and style)

Must have:

Page 4: Zend Framework 2 - presentation

Startup

Page 5: Zend Framework 2 - presentation

Basic folders structure/

config/autoload/

data/cache/log/

doc/ (documentations, md files)module/

Application/ [module_name]

config/Controller/Entity/view/ (.phtml files)

application/ [module_name]

layout/language/ (translation .po files)

Module.phppublic/

(css/ - js/ - images/ - uploads/) ...index.php

vendor/ (zendframework, doctrine-orm, ...)

Page 6: Zend Framework 2 - presentation

Modules

Page 7: Zend Framework 2 - presentation

Basic modules- Application

- ControllerPlugins- ViewHelpers- Route dynamic / Navigation- Forms (validators, filters)

- User (with Role)- Login/Logout, Registration, Activation, Forgot password- Authentication- ACL (role/ressource)- Rbac (assertions),

- Newsletter- Export: csv, xls- Social networks (sign-in, share, get/post data, ...)- E-Payment- ...

More modules

Page 8: Zend Framework 2 - presentation

Configuration- PHP Array (cacheable)

config/application.config.php (list modules to load)autoload/

*.php

Modules/config/module.config.phpModule.php (function)

Note: Overid configuration with the same name in all configuration files.

Page 9: Zend Framework 2 - presentation

Events

- bootstrap- route- dispatch- dispatch.error- render- finish

__NAMESPACE__

Page 10: Zend Framework 2 - presentation

Attach events

Note: in case of error => route ⇨ render ⇨ finish

use Zend\Mvc\MvcEvent;

public function onBootstrap (MvcEvent $e)

{

$serviceManager = $e->getApplication()->getServiceManager();

$eventManager = $e->getApplication()->getEventManager();

$sharedManager = $eventManager->getSharedManager();

$var1; $var2; ...

$eventManager->attach(MvcEvent::EVENT_ROUTE, function($e) use($var1, $var2) {..}, 100);}

$eventManager->attach(MvcEvent::EVENT_DISPATCH, function($e) {..}, 100);}

$sharedManager->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, function($e){..}, 100);}

$eventManager->attach(MvcEvent::EVENT_RENDER, function($e) {..}, 100);}

$eventManager->attach(MvcEvent::EVENT_FINISH, function($e) {..}, 100);}

}

Page 11: Zend Framework 2 - presentation

Route

Page 12: Zend Framework 2 - presentation

Static route:Types: Literal ,Segment/Regex, ...

'router' => array(

'routes' => array(

'article' => array(

'type' => 'Literal'

'options' => ...

'may_terminate' => true,

'child_routes => array(

'show' => array(

'type' => 'Regex',

'options' => array(

'regex' => '/(?<id>\d+)/(?<title>[a-zA-A-0-9_]*)',

'specs' => '/%id%/%title%',

'defaults' => array(

'__NAMESPACE__' => 'Post\Article'

'controller' => 'index',

'action' => 'show',

),

),

Page 13: Zend Framework 2 - presentation

Hierarchy organisation: child

Name Description Example

home / default page /

article /article list articles (pagination) /articles

page /page list articles (pagination /articles/page/2

show /id/[title] show article by id /article/14/lorem_ipsum

show_slug /[slug] show article by title(slug) /article/lorem_ipsum

$this->url('home');

$this->url(

'article/show',

array('id => 14, 'title' => 'lorem_ipsum'

);

Page 14: Zend Framework 2 - presentation

Dynamic routes:- navigation menu- articles Slugs

Note: this table can be used for generating navigation menu.

Page 15: Zend Framework 2 - presentation

Translation

Page 16: Zend Framework 2 - presentation

Translate static files

Zend Framework 2 resources (php array):- forms errors

Modules (use .po file):- views- controller feedback (response, errors, ...)

Page 17: Zend Framework 2 - presentation

Translate dataDoctrine2 Gedmo extension.- Attach Gedmo listener to Doctrine2 entity manager- Configure the Entity

The Good- no need to change the query code.- separate translation containers for every translated content.

The Bad- not easy to config.

The Angry- Multiple queries to fetch the content, not using Join.

Page 18: Zend Framework 2 - presentation

View

Page 19: Zend Framework 2 - presentation

ViewModelController:

use Zend\View\Model\ViewModel;

class IndexController extends AbstractControllerAction$response = array(

'success' =>

);

return new ViewModel(array($response);

<?= $response; ?>

view file:

Page 20: Zend Framework 2 - presentation

JsonModeluse Zend\View\Model\JsonModel;

class IndexController extends AbstractControllerAction

$response = array(

'success' => true, 'message' => 'Email successfully added', 'data' => array(...

);

$response = array(

'success' => false, 'message' => 'Email registration failed', 'errors' => array(...

);

$view = new JsonModel(array($response);

return $view;

Failed/Error

Success

Page 21: Zend Framework 2 - presentation

Form

Page 22: Zend Framework 2 - presentation

ACL

Page 23: Zend Framework 2 - presentation

Side projects

Page 24: Zend Framework 2 - presentation

Side projects:Script compressor:

- javascript (jslint validated)- css

Server tester:- apache modules, services (mail)- php functions

Client/Dev: better communication

Page 25: Zend Framework 2 - presentation

The End

Page 26: Zend Framework 2 - presentation

Thoughts:Backoffice module:

- layout and view- manage

User:-

Logger: (view in admin area)

FlashMessenger: (Log, Info, Warn, Error)