Building a Login Scenario
…s run this!
It runs... and fails:
The text "Logout" was not found anywhere in the text of the current page.
I happen to know this is because the password is wrong. But let's pretend that
we didn't know that, and we're…
BDD Features
…good. What else do we have? Check out the "Fence Security Activated" message on the site.
Let's imagine we need to create an API where someone can make an API request to turn the fence
security on or off from anywhere. For example, if…
The window Object & Global Variables
…like RepLogApp, this becomes a global variable. That means you can reference
RepLogApp from anywhere else, and this is actually referencing window.RepLogApp.
More on that in a second.
Inside of our self-executing function, we - of course - also have access to any global
variables…
The Magical this Variable & currentTarget
…try this: console.log(e.currentTarget === this):
Refresh! And click anywhere on the delete link. It's always true.
There's a good chance that you've been using the this variable for years inside
of your listener functions to find the element that…
Functions, Filters and Debugging with dump
…then use the number_format
to show only one decimal place:
In fact, functions and filters can be used anywhere. Let's use the length
filter to print a message if there are no penguin products for sale:
This filter takes an array or collection…
Doing Crazy things with Foundry & Fixtures
…that's now configured to create
multiple objects. Pass 1, 5 to create anywhere from 1 to 5 QuestionTag objects.
Try the fixtures again:
No errors! And if we SELECT * FROM question:
We only have 25 rows: the correct amount! That's the 20 published.…
Fetching Relations
…refresh, we should see the same list of answers.
And... we don't!? We get some PersistentCollection object. And, even stranger,
I don't see the Answer objects anywhere inside of this collection. Dude, where's
my answers?
Excellent question! Two important things here. First…
Integration Testing Emails
…the same for Twig: self::$container->get(Environment::class).
I love that! Again, the downside is that you really do need to have wkhtmltopdf
installed correctly anywhere you run your tests. That's the cost of doing this.
Before we try it, at the bottom…
Using a Base Email Template
…6 authors... or really, 6 users that
are subscribed to the newsletter... but anywhere from 0 to 6 of these might
actually have recent articles. Spin over to Mailtrap. If you don't see any
emails - try reloading the fixtures again... just in case you…
Automatic 404 on Unpublished Items
…a Mac, is the same as going to the Refactor menu
on top and selecting "Refactor this". Let's extract this logic to a "Method" - call
it addWhere.
Cool! That gives us a new private function addWhere()... and applyToCollection()
is already calling it. Do the…
Context Builder & Service Decoration
…it talks about changing the serialization context dynamically
and gives an example. Steal this BookContextBuilder code. This class
can live anywhere in src/, but to follow the docs, let's create a Serializer/
directory and a new PHP class inside of that called AdminGroupsContextBuilder...
because…
Login Success & the Session
…may make it less secure. As a general
rule, while you can use API tokens in your JavaScript, you should never store
them anywhere - like local storage of cookies due to security. That makes using
API tokens in JavaScript... tricky.
So... if we're not…
Role Hierarchy
…
But... don't worry! Symfony has our backs with a sweet feature called
role_hierarchy. Open config/packages/security.yaml. Anywhere inside, I'll
do it above firewalls, add role_hierarchy. Below, put ROLE_ADMIN set to an
array with ROLE_ADMIN_COMMENT and ROLE…
Fetch the User Object
…we can call, getEmail() on it. Do that: ->getEmail():
Cool! Move over and refresh. No errors. Click anywhere down on the web debug
toolbar to get into the profiler. Go to the logs tab, click "Debug" and... down a
bit, there it is!
Checking account…
Bootstrapping the Bundle & Autoloading
…move the KnpUIpsum class into that directory. And yea, you could
put this into a src/Service directory, or anywhere else you want.
Oh, but this namespace will not work anymore. We need a namespace that's custom
to our bundle. It could be anything…
JavaScript & Page-Specific Assets
…page,
it will appear too early - before even jQuery is included!
To add our new file at the bottom, we can override the javascripts block.
Anywhere in show.html.twig, add {% block javascripts %} and {% endblock %}:
Add the script tag with src="", start typing article_show…
Assets: CSS & JavaScript
…inside the stylesheets block?
Is that important? Well, technically... it doesn't matter: a link tag can live
anywhere in head. But later, we might want to add additional CSS files on specific
pages. By putting the link tags inside this block, we'll have…
Asset Versioning & Cache Busting
… Open config/packages/framework.yaml. Anywhere,
but I'll do it at the bottom, add assets: then json_manifest_path set to
%kernel.project_dir%/public/build/manifest.json:
This is a built-in feature that tells Symfony to look for a JSON file at…
jQuery Plugins / Bootstrap
…! This
is where things get really interesting.
At this point, we're no longer using the global jQuery variable or Bootstrap
JavaScript anywhere: all of our code now uses proper require statements. To
celebrate, remove the two script tags from the base layout:
And now…
Installation and First Admin
…which we need
to import. Copy the routing import lines, find our app/config/routing.yml and
paste anywhere:
Since we already have some pages that live under /admin, let's change the prefix
to /easyadmin:
Finally, one last step: run the assets:install command…
x
517