How to handle dynamic Subdomains in Symfony
…this be handled? Let’s find out together!
1) The VirtualHost¶
Before you go anywhere, make sure you have an Apache VirtualHost or Nginx
site that sends all the subdomains of your host to your application. Since
we’re using lolnimals.l locally, we’ll…
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…
Review this Product... in a turbo-frame!
…we submit... gorgeous! Our new review even popped up right above
the form!
Though, hmm. There's no success message anywhere on the page. There was
one before... but now it's gone! What happened?
Look back at the network tools. There are two new…
Fixing External JS + Analytics Code
…it in your browser. It's minified... so pretty
unreadable. Copy the source, close it, spin over to your editor and create a
new file anywhere, like pizza.js... we're not going to actually use this. Paste
the code, select it, then go back…
3rd Party JavaScript Widgets
…this... then go open templates/base.html.twig. Head to the
bottom and paste this in the footer: right before the closing body tag...
though you could put this anywhere.
Cool: this gives us an a tag... which just says "New York weather". Then,
my…
Fixing the Sweetalert Modal
…go forward and... it worked! Wait, I can't scroll...
and nothing is clickable! Inspect element anywhere. Uh oh: a Sweetalert backdrop
element is still there! It's invisible, but it's blocking the page!
This is the exact same problem we just saw with…
Current Product Id
…read this in a Vue component? Well... it's a global variable... so
we could put window.currentProductId anywhere. But in the last tutorial, we
started centralizing these global variables into a services/page-context.js file.
As a reminder, services/ is a directory that…
Adding a Watcher
…we didn't need it! All we needed to do - when onSearchProducts()
was called - was use the term to immediately load the products. There was
no need to store the search term anywhere for later. But now we do have a need!
We do need…
Flex Extras
…new version, your fixtures are services, and so they act
like everything else. You can even put them anywhere.
When Composer finishes, download one more package:
composer require fzaninotto/faker
This isn't needed by DoctrineFixturesBundle, but we are going to use it. In fact…
Autowiring Controller Arguments
…>get() call that
does not work with private services.
Celebrate by removing the first alias! The rest are easy!
The app.markdown_extension id isn't referenced anywhere, so remove that. The
app.security.login_form_authenticator is used in two places: security.yml
and…
Twig
…work most of the time.
It will even look inside your controller to see what kind of object it is and give you
autocomplete on its methods.
And remember, anywhere that you get autocomplete, you can hit command+space to see
all of your options…
Annotations
…bring up all the options that you
have in that spot. In fact, "control+space" can be used pretty much anywhere to show
you your auto-complete option - really handy.
This autocomplete works for two reasons. First, an annotation represents a real class.
Hold command…
Parameters
…dir? And
we'll set its value to __DIR__:
That doesn't do anything, but now we can use that root_dir parameter
anywhere else when we're building the container.
To use a parameter in Yaml, say %root_dir%:
With everything in Yaml, we…
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…
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…
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…
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…
x
511