04.
Finding and Instantiating the Controller
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
3 Comments
Hi Ryan,
Being the n00b I am to Symfony and also being the curious person I am, I went in even deeper and looked at this,
$controller = $this->parser->parse($controller);
because I didn't and still don't understand why "Action" is added to the defined function name for the controller, when using routing.yml or routing_dev.yml.
Can you explain why this is done and necessary? Is there a logical reason or is it just something Symfony imposes, as a sort of best practice? Because, I was totally confused at first. I was like, why do I need to name my function "indexAction" or "showAction" in the controller, when it is called "index" and "show" in the routing parameters. And, this little minor "strangeness" is never explained in the docs.
Scott
Hey Scott!
Nice digging :). Yes, it's just a convention that's "imposed" on you - the idea being that it helps keep your method names consistent. In reality - whether it's a good idea or not - it causes the exact confusion you're mentioning for beginners - it's a Symfony-ism to learn. That's one of (but not the only) reason why I now recommend using annotation routes.
As a side-note, now that you've been through this, you'll notice that, if you really want to, you can avoid this convention simply by putting the full class :: method name in your routing.yml:
It's not, that's why it's not too practical. But because of this format, you don't go into the if block that uses the parser - because you're already in the "final" format. You can safely remove the "Action" suffix here if you wanted to and it would work fine.
Cheers!
Thanks Ryan.
I think as I run into these "Symfony-isms" I'll jot them down and maybe make my own blog post about them.:)
Scott
"Houston: no signs of life"
Start the conversation!