Upload
yamcsha
View
1.207
Download
0
Tags:
Embed Size (px)
Citation preview
Zend Framework 2
http://slidesha.re/134YKwL
Prerequisites
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:
Startup
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, ...)
Modules
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
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.
Events
- bootstrap- route- dispatch- dispatch.error- render- finish
__NAMESPACE__
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);}
}
Route
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',
),
),
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'
);
Dynamic routes:- navigation menu- articles Slugs
Note: this table can be used for generating navigation menu.
Translation
Translate static files
Zend Framework 2 resources (php array):- forms errors
Modules (use .po file):- views- controller feedback (response, errors, ...)
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.
View
ViewModelController:
use Zend\View\Model\ViewModel;
class IndexController extends AbstractControllerAction$response = array(
'success' =>
);
return new ViewModel(array($response);
<?= $response; ?>
view file:
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
Form
ACL
Side projects
Side projects:Script compressor:
- javascript (jslint validated)- css
Server tester:- apache modules, services (mail)- php functions
Client/Dev: better communication
The End
Thoughts:Backoffice module:
- layout and view- manage
User:-
Logger: (view in admin area)
FlashMessenger: (Log, Info, Warn, Error)