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…
Users Need Passwords (plainPassword)
…little evil.
Finally, in eraseCredentials(), add $this->plainPassword = null:
Symfony calls this after logging in, and it's just a minor security measure to prevent
the plain-text password from being accidentally saved anywhere.
The User object is perfect. Let's add the listener.
The Form Type Class
…in the new GenusAdminController.
To create a form, you'll add a class where you'll describe what the form
looks like.
In PhpStorm, select anywhere in your bundle and press command+N, or right click
and select "New". Find "Form" and call it GenusFormType…
dotenv: Environmental Variables
…Because of config.yml,
this should turn the toolbar off. Change the environment to prod too - that's not
being used anywhere yet, but it may avoid a temporary cache error:
Try it out: no web debug toolbar.
Add .env to the .gitignore file - this…
AppBundle, Routing and Annotations
…some comments to make things really small. This includes the normal
autoloader, then adds an extra thing for annotations. Now, in index.php - or anywhere
else you need to autoload - require this file instead:
Refresh! Very nice! Let's count the files: 1, 2, 3…
The All-Important HttpExceptionInterface
…error, unless
that exception implements the HttpExceptionInterface:
It has two functions: getStatusCode() and getHeaders(). The HttpException class
we're throwing implements this. That means we can throw this from anywhere in our
code, stop the flow, but control the status code of the response. Symfony…
Mad Test Debugging
…is really easy. The class that handles the
styling is called ConsoleOutput, and you can use it directly from anywhere.
Start by adding a private $output property that we'll use to avoid creating
a bunch of these objects. Then down in printDebug(), say
if…
Deployment
…under a branch called episode4-finish.
Let’s clone this repository:
git clone
Move into the directory. If your code lives anywhere other than the master
branch, you’ll need to switch to that branch:
git checkout -b episode4-finish origin/episode4-finish
GitHub might…
Remember Me Functionality
…our session cookie to make sure it’s working. When I refresh,
my session is gone but I’m still logged in. Nice! Click anywhere on the web
debug toolbar to get into the profiler. Next, click on the “Logs” tab. If
you look closely…
Block Views & Block Definitions
…the newest first and limit to 3.
Ok, if we "Publish and continue editing"... then refresh... whoa! It's cool that
we can just put those anywhere now. Though, let's wrap that in a container. And...
much better.
So far, this is all easy…
Shared Layouts
…new layout, I'll choose my favorite layout 2 and call it
"Recipes List Layout". To start, add a new block called "Full View"... and drag it
anywhere onto the page, whoops! There we go.
What is this "Full View". It's nothing special, in…
Item View Template
…our recipe item:
Next, add recipes_app... with a little note to say that this key is not important:
Unlike other things, such as latest_recipes, this internal key won't be used
anywhere. Below, we need two important things. First, template - don't include…
Toast Notifications
…and add another review. This time... that's super
cool! And it means that we can, from anywhere, render the _toast.html.twig
template and it will activate this behavior.
Though... the positioning isn't what I was imagining. Before it disappeared, it
was open…
Ajax Element Reloading Controller
…an Ajax call to reload the product list area after a new product is successfully
added. To be extra cool - cause we are extra cool - we're going to make this
new controller generic so we can reuse it anywhere... like on the cart page…
Symfony UX & Chart.js
…I've already created that page at
"/admin"... but it's not very interesting yet... and none of these links go anywhere.
Ok: let's check out the docs for Symfony UX chartjs. Scroll down... Whoa.
Stimulus and Chart.js are both pure JavaScript libraries…
Parameters
…the container. Invent a new one called, how about,
cache_adapter set to cache.adapter.apcu:
There should now be a new parameter in the container called cache_adapter.
We're not using it anywhere... but it should exist.
How do we use it? There…
Creating a Service
…which we will later.
So how do we create our very own service? Start by creating a class anywhere in
src/. It doesn't matter where but I'll create a new sub-directory called Service/,
which I often use when I can't think…
FlattenException & Error Status Codes
…which will be a 412 and many more.
Hmm, where's the IAmATeaPotHttpException?
If you throw any of these exceptions from anywhere in your app, they will trigger
an error page with the correct status code. This is a powerful thing to understand.
Back in…
Sub Request Attributes
…argument. If we try, I want
an exception to be thrown.
By the way, it is actually possible to use the RequestStack from anywhere
to get the "master" request: it has a getMasterRequest() method. But! If
you're using HTTP caching with edge side includes…
Calling the Controller & View Event
…entity! You would return a "model". Then, you could write a listener
to this event that transforms that Article entity into HTML by rendering the template.
This event isn't used anywhere in Symfony's core, but it is used extensively
inside API Platform. Internally…
x
513