0% found this document useful (0 votes)
223 views

Zend Framework 2 MVC Workflow

The summary outlines the three main parts of the Zend Framework 2 MVC workflow: 1) initialization of the ServiceManager, 2) initialization of modules, and 3) starting the MVC process including bootstrapping, routing, dispatching, and sending the final response.

Uploaded by

jyotirs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
223 views

Zend Framework 2 MVC Workflow

The summary outlines the three main parts of the Zend Framework 2 MVC workflow: 1) initialization of the ServiceManager, 2) initialization of modules, and 3) starting the MVC process including bootstrapping, routing, dispatching, and sending the final response.

Uploaded by

jyotirs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

2/9/2016

Zend Framework 2 MVC workflow

Programering
Home|Questions|Articles
ZendFramework2MVCworkflow
adsbyYahoo!

adsbyYahoo!

ApplicationDevelopment

CloudComputingBooks

ComputerProgramming

ComputerProgramming

FreePDFBooks

ITCertificationCourses

NetworkSecurityBooks

CloudComputingBooks

Catalog
Summary
Thefirstpart:theinitializationofServiceManager
Thesecondpart:initializationmodule
Thethirdpart:startMVC
Bootstrapbootstage
ThestructureofZend\View
TheinitializationofZend\View
ThestartupphaseofMVC
Routeroutingstart
Dispatchdistribution
SendingthefinalresponseandfinishMVC
Summary
Firstneedtobeclear,Zend2.0andthestartoftheMVCframeworkisentirelybasedoneventdriven.Iftheevent
drivenstilldon'tknowthewords,shouldfirstmakeclearwhatistheZF2eventdriven,andmastertheusageof
EventManagerbasic,thisisthebasisofreadingthis.PleaserefertotheUsingtheZF2EventManager.

NetworkSecurityBooks

BasedontheeventdrivenMVCandtraditionalMVChavewhatdifferent,simplybycomplexprocessflow.The
traditional.Intotheeventregistersomewhere,thentriggerthesimpletwoelementrelationsbetweeneventsin
somewhere,theeventisnotaffectedbythestructureofthecodeandthecallflow,canbeuncoupledconveniently.

DiscountComputerMonitors

FreePDFBooks
ApplicationDevelopment
ITCertificationCourses
DiscountPrinters
RefurbishedComputers
BestGamingComputers

CheapDesktop

IntherecentlyintroducedServiceManagerandZend1noconcept,inmyunderstanding,theintroductionof
ServiceManageristheZF2developmentteamfortheintroductionofDimetadataprogrammingproblems
(Metaprogramming)isakindofreflection.

BestTabletPCs

ThebenefitsofServiceManageris:

BestLaptopDeals

ThemainpartofthewholeZendarchitectureoftheimage,makestructuremoreorganized,moreconduciveto
understanding
TosimplifytheconfigurationofDi,reducethelearningcost
FurtherweakenstheBootstrap,letstheentirestartupprocessmoreconcise
ServiceManagerbringsthedisadvantageis:

ExternalHardDrives
CheapComputerParts

AlayerofpackagingwillbeDi,notthroughtheconfigurationfiletocontroltheentireframedirectly
Customwhenthedemandisrelativelyhigh,butimprovethelearningcost,becausetheDiinlearningandlearning
ServiceManager
Sogossipsofar,begantoentertherealZend2.0MVCskeletonprocessanalysis,heretoZendSkeletonApplicationin
May21stasanexample:
Thefirstpart:theinitializationofServiceManager
ZendSkeletonApplication/public/index.php
$configuration=include'config/application.config.php'
$serviceManager=newServiceManager(newServiceManagerConfiguration($configuration['service_manager']))
$serviceManager>setService('ApplicationConfiguration',$configuration)
Basicconfigurationfiletoreadtheentireapplication,initializetheMvcframeworkrequiredbytheServiceManager.
ThedefaultdependsontheprocessofalltheclassesarewritteninZend\Mvc\Service\ServiceManagerConfiguration.
ServiceManagerinteriorisdividedinto5categories
TheservicesService
Factoriesfactory
AbstractFactoriesAbstractFactory
Thealiasesalias
Sharedsharedservice
Thedefaultconfigurationoftheprojectconfigurationfileapplication.config.phpwilloverrideZendandload,for
example,ifyouneedtouseacustomservice,youcanwriteitintheconfigurationfile
<?php
returnarray(
'service_manager'=>array(
'use_defaults'=>true,
'services'=>array(
'ViewManager'=>'EvaEngine\Mvc\View\ModuleViewManager',
),
),
)
Thesecondpart:initializationmodule
ZendSkeletonApplication/public/index.php
$serviceManager>get('ModuleManager')>loadModules()
InServiceManagerModuleManager,isessentiallyaZend\Mvc\Service\ModuleManagerFactorypackage,themain
workincludes:
Listtoloadmoduletoobtaintheprojectconfigurationfile
Accordingtotheconfigurationofergodicmodule,respectivelyloadingmoduleconfigurationfile
Mergemoduleconfigurationfile
Intheconfigurationfile,canthroughthemodulesnodecontrolwhichmodulesspecificload.
Moduleloadusingthesameeventdriven,realizedbymodulemanagerZend\ModuleManager\ModuleManager
moduleeventZend\ModuleManager\ModuleEvent,whichinturntriggersintheprocessofloadingmodule
AllloadModules.premodulesbeforeloading.

http://www.programering.com/a/MTM0cTMwATI.html

1/3

2/9/2016

Zend Framework 2 MVC workflow

EachloadModule.resolvemoduleloading
EachloadModulemoduleafterloading
AllloadModules.postmoduleafterloading
Thethirdpart:startMVC
FinallytotheMVCpartofMVC,thewholeprocessisaccompaniedbyeventdriven,ZF2whichisdefinedastheMVC
event,inaccordancewiththeexecutiveorderincludes:
BootstrapGuide
Routerouting
Thedispatchdistribution
Renderrendering
Theendoffinish
Soinordertofacilitatethedescription,will
ZendSkeletonApplication/public/Index.php
$serviceManager>get('Application')>bootstrap()>run()>send()
Splitintothreestages
Bootstrapbootstage
$app=$serviceManager>get('Application')>bootstrap()
InZend1,theBootstrapwasthecorepartofMVC,inZF2,duetotheintroductionofeventdriven,thispartbecomes
verysimpleandclear:
FirstinZend\Mvc\Applicationbootstrap(),registrationofallMVCevents,theinitializationofMvcEvent
(Request/Response/Routerinjection),andtriggerthebootstrapevent.
Inthisprocess,theViewpartoftheinitializationisrelativelycomplex,describedseparatelyasfollows
ThestructureofZend\View
InZF2,Viewalsomadechanges,verylargeLayout,HelperareincorporatedintotheView.InZend1,Layoutisthe
componenthasanindependent,andZF2,LayoutandTemplatecalledViewModel,ViewModelisatreestructure,
whichcanberecursivelynestedtemplates,andintheZF2Layout,isatthebottomofthetreestructureofViewModel.
TheZF2Viewconsistsofthefollowingparts,calledAlloVincepersonaltranslation,inappropriateplease.:
TheView\Viewview,mainlytotakeovertheMVCincident
TheView\Strategystrategy,themaincontainerPlaceholdersoverallarrangementofview,alsowillbetheultimate
resultviewintoacontainer,splitforpresentationtotheuser'slast
View\Resolverdecisionmaking,defineatemplatenamemappingrelationshipwiththeactualpath,atthesametime
todeterminetheactualfiletemplatefinalcorresponding
View\Rendererrenderer,theassistantdecisiondevice,convertViewModeltotextoutput.Arenderermustcorrespond
toadecisionmakercanwork.
TheView\Modelviewmodel,includingallvariablesmaybeusedintheview.Itsasatreestructure,aviewmodelcan
containseveralsubmodel
TheView\Helperviewhelper,generationHTMLTags
IntheMVCarchitecture,Zend\Mvc\View\ViewManagerwillintegratealloftheaboveparts,finallyformthewhole
view.
TheinitializationofZend\View
Gobacktothepreviousday,whenthebootstrapeventistriggeredintheviewofsomeofthemainpart,dothe
preparatorywork,including:
SpecifyaMVCspecificstrategiesforZend\Mvc\View\DefaultRenderingStrategy,Layoutdefinedinthisstrategywillbe
thetopViewModel.MvcEvent::EVENT_RENDEReventregistration
IntothetemplateZend\Mvc\View\InjectTemplateListenermonitor,themostimportantistheroleoftheControllerand
Actionnametogeneratethedefaultviewname
InjectionofviewmodelmonitoringZend\Mvc\View\InjectViewModelListener
Sowecandrawtheconclusion,bootstrapphaseintheZendMvcview,allpreparationsarealreadyinplace,andnot
waituntiltheendorstartControllerrouting.Thepointiswhentheroutingfailure,stillcanhavethecorrespondingview
toshowabnormalresults.
ThestartupphaseofMVC
ZendSkeletonApplication/public/index.php
$response=$app>run()
Thestartupphasecorrespondingtotheevent
Routerouting
Thedispatchdistribution
Ifanexceptionoccurs,itwillbeaheadoftheendofthebootprocess,distributionofeventsmaynottriggerandtrigger
eventfinish(end).
Routeroutingstart
ReconstructionofZF2routingthemostmeaningfulistoallowroutingtreestructurearrangement,setprioritycan
routebetween.BriefintroductioncanrefertoIntroducingZendFramework2Router.SoZF2routingcanbe
respectivelyarrangedineachmodule,andalsocanimprovetheprioritylevelinsomemodule.Itisverysuitablefor
largescaleapplicationdeployment.
Routinginthestartupprocess,Zend\Mvc\RouteListeneronRoute()istriggered,aroutefromthetreestructure
matching,andultimatelyoneofthemostadaptiveroutingtoreturnintheformofaZend\Mvc\Router\RouteMatch
object.
Dispatchdistribution
ZF2Dispatchdistributionactuallyhastwo,oneisintheZend\Mvc\Application,theaimistomatchtheRouteMatch
throughtheparametertoaspecificController,theotherintheZend\Mvc\Controller,theaimistoRequest/Response
injection,runthecorrespondingAction.
Theprocessisasfollows
//Distributedeventtriggered
Zend\Mvc\DispatchListener>onDispatch()
//Accordingtotheparametermatchinglocationroutingtoacontroller
$controller=$controllerLoader>get($controllerName)

http://www.programering.com/a/MTM0cTMwATI.html

2/3

2/9/2016

Zend Framework 2 MVC workflow

//Triggerthecontrolllerdispatch
$return=$controller>dispatch($request,$response)
SendingthefinalresponseandfinishMVC
ZendSkeletonApplication/public/index.php
$response>send()
Afterthedistribution,ifthecorrectresponseisobtainedfromcontroller,willcontinuetorun
Zend\Mvc\Application>completeRequest()
ThiswilltriggertheMVCeventofthelasttwo
Renderrendering
Theendoffinish
//CalltheMVCdefaultpolicyfortherenderevent
Zend\Mvc\View\DefaultRenderingStrategy>render()
TheRendereventintegratingvariouspartsofZend\View,eventuallyassembledintoa
Zend\Http\PhpEnvironment\Response,senttotheuser.
ThisisthecompleteprocessofZend2.0MVC.
adsbyYahoo!

ApplicationDevelopment

CloudComputingBooks

ComputerProgramming

FreePDFBooks

ITCertificationCourses

NetworkSecurityBooks
PostedbyJessieatMarch26,20144:39PM

Team

ApplicationDeployment

DecisionMakers

Defined

Arranged

Disadvantage

BootProcess
Essentially

CustomService

EventDriven

Team

2016ProgrameringContactUs

http://www.programering.com/a/MTM0cTMwATI.html

3/3

You might also like