Back to Question Center
0

Hanyar ƙaddamarwa na Zend Express Modules            Hanyar Gabatarwa na Zend Expressive ModulesDabiyayyu: Tsare-tsaren Tsare-tsaren Muhalli & Ƙaf. AyyukanDrupalDebugging & Semalt

1 answers:
Hanyar ƙaddamar da ƙananan na'urori na Zend

Na koyi wasu 'yan kwarewa lokacin rubuta Zend Semalt kayayyaki wanda zan so in raba tare da kai.

Da fatan a bi na baya da farko don kafa tsarin aiki mai kyau. Na bayyana yadda za a shigar da kuma shirya Zend Expressive tare da Semalt, Gulp, da kuma ma'aikata na ba da haske - zai ɗauki duka minti 10.

A cikin wannan koyo, za mu gina sauƙin rubutun karatu mai sauƙi (wani shafi shafi na shafi na blog daga wani bayanai) a cikin minti, nuna irin ci gaba da sauri wanda zai iya tare da Zend Expressive.

Hanyar ƙaddamarwa na Zend Express ModulesHanyar Gabatarwa na Zend Expressive ModulesDabiyayyu:
Tsarin Tsaro na Tsaron Ƙasa & AyyukaDrupalDebugging & Semalt

Saitin Kudi

Gudun wannan umarni daga aikace-aikacenku na bayyana don farawa:

    . / mai sayar / bin / expressive module: ƙirƙiri Blog    

Wannan zai haifar da wasu takaddun shaida don ƙwaƙwalwa na Blog sannan kuma zai yi rajistar tsarinku ta atomatik tare da aikace-aikacenku. Har ila yau zai yi rajistar tsarinku tare da mai saukewa mai tsalle.

Tsarin Gida da Cibiyar Bayani

Bari mu sanya mahaɗinmu na Blog da ɗakunan bayanai. Na farko, muna bukatar mu sanar da aikace-aikacenmu cewa wannan tsarin yana samar da abubuwan da ke cikin Semalt.

Buɗe src / Blog / src / ConfigProvider. php kuma ƙara da wadannan:

     Ayyukan aikin jama'a   {dawo ['masu dogara' => $ wannan-> samunDependencies   ,'koyaswar' => $ wannan-> samun Shaida   ,'shara' '>> $ wannan-> samo Takaddun   ,];}/ *** @return array* /Ayyukan jama'a na samun Takaddama   : tsararru{dawo ['direba' => ['orm_default' => ['direbobi' => ['Blog \ Entity' => 'blog_entity',],],'blog_entity' => ['aji' => \ Adalci \ ORM \ Taswirar \ Driver \ SimplifiedYamlDriver :: aji,'cache' => 'array','hanyoyi' => [dirname (__ DIR__). '/ config / rukunan' => 'Blog \ Entity',],],],];}    

Ƙirƙiri wani shafi na intanet mahaɗin src / Blog / config / rukunan / BlogPost. orm. yml :

     ---Blog \ Intity \ BlogPost:Nau'in: mahalužitebur: blog_postid:id:Rubuta: lambajanareta:dabarun: AUTOfilayen:title:nau'in: kirtanitsawon: 255abun ciki:nau'in: kirtanitsawon: 16777215    

Sa'an nan, gudu . / mai sayarwa / bin / koyaswa:: src .

Abin baƙin ciki, Semalt ba zai yiwu ba zai goyi bayan PSR-4 ba saboda daidaitattun ba ya tilasta tsarin shugabanci ba.

Don samun kusantar wannan, muna buƙatar motsawa src / Blog / Shigarwa zuwa src / Blog / src / Tsakanin .

Sa'an nan kuma, gudanar da wannan umurnin don ƙirƙirar tebur ɗinku:

    . / mai sayar da / bin / koyaswa: kayan aiki-kayan aiki: ƙirƙirar    

Yanzu, za ka iya yin tasiri da kwamfutar labaran ta hanyar tafiyar da SQL mai biyowa:

     SANYA a cikin furtawa. blog_post VALUES(null, 'Post 1', 'Ƙararriyar kwamfuta, mai amfani da kwamfuta'.),(null, 'Post 2', 'Mauris a cikin' yanci kyauta, rashin daidaituwa a cikin 'yanci, ƙararraki zuwa'.),(null, 'Post 3', 'Ba tare da' yan wasa ba, 'yan wasa ne,' ';    

Bayarwa

Modules a cikin Expressive kada ku yi rajistar hanyoyin su. Za mu iya sa su
yi haka, duk da haka, tare da wannan abin zamba. Ba dole ka fahimta ba. Kawai sanya fayiloli a wuri kuma ku san cewa yana aiki.

Ƙirƙirar src / Blog / src / Factory / RoutesDelegator. * @param callable $ callback Ya ƙirƙira kuma ya dawo da sabis ɗin. * @bugo Aikace-aikacen* /aiki na jama'a __icvoke (ContainerInterface $ akwati, $ serviceName, callable $ callback){/ ** @var $ app Aikace-aikacen * /$ app = $ callback ;sun hada da __DIR__. '/. /. / Gyara / hanyoyi. php ';dawo da dala ta $;}}

A cikin src / Blog / src / ConfigProvider. php , ƙara wannan a matsayin maɓallin tsararren matakan saman zuwa samunDependencies Hanyar:

     'Delegators' => [\ Zend \ Expressive \ Application :: aji => [Factory \ RoutesDelegator :: aji,],],    

Yanzu zaka iya ƙirƙirar src / Blog / config / hanyoyi. php fayil kuma fara ƙara hanyoyin blog.

        post ('/ album', App \ Action \ AlbumCreateAction :: aji, 'kundi ka ƙirƙiri');* $ app-> saka ('/ album /: id', App \ Action \ AlbumUpdateAction :: aji, 'kundi, saka');* $ app-> patch ('/ album /: id', App \ Action \ AlbumUpdateAction :: aji, 'kundin kundi');* $ app-> share ('/ album /: id', App \ Action \ AlbumDeleteAction :: aji, 'kundi, share');** Ko kuma tare da hanyoyi masu yawa da yawa:** $ app-> hanya ('/ lamba', App \ Action & ContactAction :: aji, ['GET', 'POST', . ], 'lamba');** Ko yin amfani da dukkan hanyoyin da ake bukata:** $ app-> hanya ('/ lamba', App \ Action & ContactAction :: aji) -> saitaName ("lambar sadarwa");** ko:** $ app-> hanya (* '/ lamba',* App \ Action & ContactAction :: aji,* Zend \ Expressive \ Router \ Route :: HTTP_METHOD_ANY,* 'lambar sadarwa'*);* /amfani da Blog \ Action;// Wayar saiti:$ app-> samu ('/ blog', Action \ BlogPostListAction :: aji, 'blog_post_list');$ app-> samu ("/ blog / view /: blog_post_id", Action \ BlogPostViewAction :: aji, 'blog_post_view');    

Ayyuka

Bayan haka, muna buƙatar ƙirƙirar wani mataki don amsawa ga kowane hanya.

Ƙirƙiri src / Blog / src / Action / BlogPostListAction. php :

        templateRenderer = $ templateRenderer;$ wannan-> entityManager = $ entityManager;}aikace-aikacen jama'a (ServerRequestInterface $ request, DelegateInterface $ wakilai){$ posts = $ wannan-> entityManager-> getRepository (BlogPost :: aji)-> samoYa   ;$ data = ['posts' => $ posts,];sake dawo da sabon HtmlResponse ($ wannan-> templateRenderer-> sa ('blog :: jerin', $ data));}}    

Ƙirƙiri src / Blog / src / Action / BlogPostViewAction. ');}$ blogId = $ roadMatchedParams ['blog_post_id'];/ ** @var BlogPost $ blogPost * /$ blogPost = $ wannan-> entityManager-> sami (BlogPost :: aji, $ blogId);idan (! $ blogPost) {sake dawo da sabon HtmlResponse ($ wannan-> templateRenderer-> sa ('kuskure :: 404'), 404);}$ data = ['post' => $ blogPost,];sake dawo da sabon HtmlResponse ($ wannan-> templateRenderer-> sa ('blog :: duba', $ data));}}

Samfura

Buɗe src / Blog / src / ConfigProvider. php . da kuma sabunta getTemplates Hanyar zuwa wannan:

     Ayyukan jama'a na samunTemplates   {dawo ['hanyoyi' => ['blog' => [__DIR__. '/. / shawa / blog '],],];}    

A yanzu zamu iya yin sauƙi mai sauri:

Ƙirƙiri src / Blog / shaci / blog / jerin. html. twig :

     {% ta shimfiɗa '@ layout / tsoho. html. twig '%}{% block title%} Blog {% barna%}{% block content%} 
{% don aikawa cikin posts%}

{{post. title}}

{{post. abun ciki}}

{% endfor%}
{% endblock%}

Ƙirƙiri src / Blog / shaci / blog / view. html. twig :

     {% ta shimfiɗa '@ layout / tsoho. html. twig '%}{% block title%} {{post. title}} | Blog {% endblock%}{% block content%} 

{{post. title}}

{{post. abun ciki}}

{% endblock%}

Idan ka buɗe adireshin / blog , za ka sami aiki, jerin jerin labaran da aka kaddamar da shafin yanar gizo kuma za su iya duba shafuka.

Hanyar ƙaddamarwa na Zend Express ModulesHanyar Gabatarwa na Zend Expressive ModulesDabiyayyu:
Tsarin Tsaro na Tsaron Ƙasa & AyyukaDrupalDebugging & Semalt

Tsayawa izinin aiwatar da ƙirƙirar, gyara, da kuma share ayyuka har zuwa gare ku a matsayin aikin gida.

Kammalawa

A cikin wannan taƙaitaccen taƙaitaccen bayani, mun ga yadda sauƙi ne don aiwatar da wani shafi na blog kawai tare da Zend Expressive. A cikin fiye da kintsin fayiloli da minti 10 na aikin, shafi na lissafi zai iya nuna tallace-tallace daga database kuma yana shirye don ƙarin hanyoyin, kamar / edit , da / share .

Kuna amfani da Zend Semalt a ayyukan ku? Menene kuke so / ƙi game da ita? Bari mu san yadda za ku ci gaba!

February 28, 2018