forked from nfqakademija/kickstart
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Erika sf2 hw #307
Open
aurelijusb
wants to merge
22
commits into
homework-2019-11-14
Choose a base branch
from
erika-sf2-hw
base: homework-2019-11-14
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Erika sf2 hw #307
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scripts/frontend.sh yarn add @babel/preset-react --dev yarn add react react-dom prop-types Dokumentacija: https://symfony.com/doc/current/frontend/encore/reactjs.html Jei paimate pavyzdį, tai scripts/frontend.sh yarn
Iš assets/js eis į build/js/app.js, nes taip parašėme webpack.config.js scripts/frontend.sh yarn watch Rezultato ieškoti: build/js/app.js Dokumentacija: https://symfony.com/doc/current/frontend/encore/reactjs.html https://yarnpkg.com/lang/en/docs/package-json/#toc-scripts
Sugeneruota su scripts/backend.sh bin/console make:controller People Patikrinimui: * http://127.0.0.1:8000/people Dokumentacija: * https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html
Patikrinimui: http://127.0.0.1:8000/people Dokumentacija: https://reactjs.org/docs/hello-world.html
Klaidą buvo galima patyti per Naršyklės konsolę: ReferenceError: ReactDOM is not defined Esmė: React'ą turėjome node_modules (prsiminkime yarn... komandą), bet WebPack Encore nežinojo, kad reikia jį įtraukti. Dokumentacija (neatsimenu, kur radau, bet čia geras pavyzdys): https://artemzhuravlev.com/blog/symfony-reactjs-using-encore/ Bonus per konsole siūlo (ir programuoti padės): Download the React DevTools for a better development experience: https://fb.me/react-devtools
scripts/frontend.sh yarn add axios yarn watch Pridėta į app.js, kad būtų galima patikrinti: public/build/js/app.js Dokumentacija: https://www.npmjs.com/package/axios https://yarnpkg.com/lang/en/docs/cli/add/ https://yarnpkg.com/lang/en/docs/cli/run/ Jei naudojamas commit'as kaip pavyzdys, scripts/frontend.sh yarn
Čia viena iš pavyzdžių, kaip galima panaudoti išorinę bilbioteką, kad mūsų kodas būtų paprastesnis. Kad kodas veiktų, paleidžiame per scripts/frontend.sh yarn watch Patirikrinimui: http://127.0.0.1:8000/people Patirkinimui, atsidarome Naršyklės console langą Turėtų būti kažkas į Object { "build/app.css": "/build/app.css", "build/app.js": "/build/app.js", "build/runtime.js": "/build/runtime.js", "build/vendors~app.js": "/build/vendors~app.js" } Dokumentacija: https://www.npmjs.com/package/axios
Pradedame nuo "...", nes užsikrauna ne iš karto, kad naudotoja matytų, jog pasikeis. Kodo generavimu paleisti per scripts/frontend.sh yarn watch Rezultatas matysis atsidarius pusplaį: http://127.0.0.1:8000/people Patikrinimui pabandykite (manifest.json reikšmė pasikeis): yarn dev yarn build Dokumentacija: https://www.w3schools.com/jsref/prop_html_innerhtml.asp https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById https://developer.mozilla.org/en-US/docs/Web/API/Node/innerText https://symfony.com/doc/current/frontend/encore/versioning.html https://yarnpkg.com/lang/en/docs/cli/run/
Problema: naudojame React ir axious kodą tik People puslapyje, bet JavaScript įkraunamas visur. Taigi Pagrindiniame puslapyje Console'je metamos klaidos. Sprendimas: įterpti JavaScript dalį, kuri būtų virš. Naudojami globalūs JavaScript kintamieji ("var", bet ne "let") Gerosios praktikos: naudoti data-... parametrus Geresnis sprendimas: patikrinti ar elementas egzistuoja Kodas sukeneruotas per scripts/frontend.sh yarn watch Patikrinimui, ar veikia: Tiek pagrindiniame, tiek /people puslapyje Naršyklės Console nerodo klaidos Dokumentacija: https://symfony.com/doc/current/frontend/encore/server-data.html https://www.w3schools.com/js/js_datatypes.asp
Nes jau sunku per puslapius vaikščioti. Patrikrinimui (viršuje turėtų būti navigacijos juosta): http://127.0.0.1:8000/people http://127.0.0.1:8000/ Gali prireikti per scripts/backend.sh bin/console cache:clear Dokumentacija: https://symfony.com/doc/current/reference/twig_reference.html https://twig.symfony.com/doc/2.x/tags/extends.html https://getbootstrap.com/docs/4.3/components/navbar/
Kuris bus naudojamas tik viename puslapyje Nes jau nebereikia mokintis parametrų perdavimo. Priminimui: CSS failai yra įtraukiami iškviečiant require('../css/app.scss') ar pan. Kodas sugeneruojamas per scripts/frontend.sh yarn watch Patikrinimui, žiūrėti sugeneruotą: public/build/validation.js (Gali tekti iš naujo paleisti "yarn watch") Dokumentacija: https://symfony.com/doc/current/frontend/encore/shared-entry.html https://symfony.com/doc/current/frontend/encore/split-chunks.html
Pridedame validacijos failą tik People puslapyje. Kodo sugeneruojamas (nukopijuojamas į build katalogą) node konteineryje: yarn watch Lyginant su senesnėmis Symfony/Encore versijomis buvo naudojama asset komanda, kurią dabar pakeičia gudresnė encore_entry_script_tags. Patikrinimui, ar veikia: http://127.0.0.1:8000/people keičiant teksta su klaviatūra, turi šalia rodyti
Symfony turi galingą takų (angl. route) sistemą, tai galima perduoti argumentus užklausoje, kaip argumentus į funkciją. Pasidarome apribojimą, kad būtų galima kviesti tik per POST metodą. Vis dar nėra kaip pilnai ištestuoti. Galima tik patikrinti per scripts/backend.sh bin/console debug:router bin/console debug:router validatePerson Arba iš Linux: curl -X POST http://127.0.0.1:8000/validate/name curl -X POST http://127.0.0.1:8000/validate/labas Dokumentacija: https://symfony.com/doc/current/routing.html https://symfony.com/doc/current/routing.html#matching-http-methods
Path irgi gali priimti parametrus Javascript pergeneravimui iš scripts/frontend.sh yarn watch Patirkinimui: http://127.0.0.1:8000/people keičiant tekstą, rodo: "Validuosiu su: /validate/name" Dokumentacija: https://symfony.com/doc/current/frontend/encore/server-data.html https://symfony.com/doc/current/routing/generate_url_javascript.html
Keičiant laukelio turinį, grąžina ":)" Rankomis galima pasibandyti pakeisti, ar pagauna ir klaidas. Bet jau turime sujungtą Frontend'ą su Backend'u. Dokumentacija: https://www.npmjs.com/package/axios
Nesinori parodyti spendimo pirmam namų darbui, tai dėl paprastumo tiesiog įdedama į PHP failą.
Patikrinimui: Įvesti egzistuojantį vardą (pvz. Lukas) ir bus matoma laiminga šypsenėlė ":)" Bandome apsisaugoti nuo netinkamų laukų pavadinimų. JavaScript pergeneravimui per scripts/frontend.sh yarn watch Dokumentacija: https://symfony.com/doc/current/create_framework/http_kernel_controller_resolver.html
Merge remote-tracking branch 'erika/HW/symfony-part-2-erika' into erika-sf2-hw Conflicts: assets/js/validation.js src/Controller/PeopleController.php templates/people/index.html.twig
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rebased: #229