10.
Code Generation FTW!
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.
8 Comments
Great tutorial! Thank You!
I have two problems.
This is a code from this lesson:
// src/Yoda/EventBundle/Controller/Event.php
// ...
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('EventBundle:Event')->find($id);
if (!$entity) {
throw $this->createNotFoundException('No event with id '.$id);
}
// ...
return $this->render('EventBundle:Event:index.html.twig', array(
'event' => $event,
'delete_form' => $deleteForm->createView(),
));
}
In your code, EventController actions don't send $entities in its responses. Instead they send $event. But there are no $event in the views. Is this a mistake or I don't understand something? Because the code from this lesson doesn't work for me.
I've changed $event in the controller to $entity and everything started to work well except google maps. Instead google map I see only broken image. This is second problem.
Please help me to fix this.
Thank You!!!
Hey Alex,
Thanks for reporting this! You're right, it should be $entity instead of $event. But what about broken image instead of google map - I can't reproduce this bug... Did you have an active internet connection? Have you tried to run the downloaded code from the "finish/" directory? Is there google map image broken for you too? Could you debug a bit more and send me the URL of google map image which is broken for you?
Cheers!
Hi KNP!
It is possible to generate CRUD based on a field other than id? Because I'd like to have URLs like /blog/about-symfony, /blog/about-php, etc (slugs), instead of /blog/1, /blog/2, etc. And, is this a correct approach or is considered a hack?
Thank you!
Hi Dan,
I suppose you aware about generate:doctrine:crud command, but it's impossible with it. Probably there's could be a bundle for what you want already, but I don't know this exactly. However you can use this command to generate CRUD based on IDs and then tweak generated code with slugs - actually, it's not a big deal. ;)
Cheers!
Hi Lucas!
If you own or have a subscription, you'll find a download button on the upper right of this page. But if you don't, you can find the "starting" version of the code (which includes the resources/ directory with the CSS stuff) here: https://github.com/knpunive...
Let me know if that gives you what you need :)
Hey Ryan,
i copied the tutorial code but nothing changed. The template's looks like before. Do you know why? I added the Rendering Call Graph maybe it helps.
main 5.87ms/100%
└ EventBundle:Event:show.html.twig 4.89ms/83%
│ └ ::base.html.twig 4.84ms/82%
│ └ EventBundle:Event:show.html.twig::block(body) 4.75ms/81%
│ └ form_div_layout.html.twig::block(form) 1.01ms/17%
│ └ form_div_layout.html.twig::block(form_start)
│ └ form_div_layout.html.twig::block(form_widget)
│ │ └ form_div_layout.html.twig::block(form_widget_compound)
│ │ └ form_div_layout.html.twig::block(widget_container_attributes)
│ │ └ form_div_layout.html.twig::block(form_errors)
│ │ └ form_div_layout.html.twig::block(form_rows)
│ │ │ └ form_div_layout.html.twig::block(button_row)
│ │ │ │ └ form_div_layout.html.twig::block(submit_widget)
│ │ │ │ └ form_div_layout.html.twig::block(button_widget)
│ │ │ │ └ form_div_layout.html.twig::block(button_attributes)
│ │ │ └ form_div_layout.html.twig::block(hidden_row)
│ │ │ └ form_div_layout.html.twig::block(hidden_widget)
│ │ │ └ form_div_layout.html.twig::block(form_widget_simple)
│ │ │ └ form_div_layout.html.twig::block(widget_attributes)
│ │ └ form_div_layout.html.twig::block(form_rest)
│ └ form_div_layout.html.twig::block(form_end)
│ └ form_div_layout.html.twig::block(form_rest)
└ @WebProfiler/Profiler/toolbar_js.html.twig
└ @WebProfiler/Profiler/base_js.html.twig
Thank you
Hey Ryan. It think i solved it now. I added a control line eg <h1>new</h1> at the top of the {%block body%} in the create template and it works after that. This is a little bit strange i swear i don't changed a pice of the logic and now it works :) But why does it work after adding this little bit of code.
Hey Florian!
Ah, I'm glad it works! You know, *sometimes* (and it is very rare) Symfony will incorrectly *not* reload cached files (like Twig templates). It's possible that Symfony was still using your old cached templates until you finally modified the file again, which triggered the template's "modified date" to change (which is how Symfony knows it should reload this file fresh). So, I think you're probably not crazy - just a weird cache thing ;).
Cheers!
"Houston: no signs of life"
Start the conversation!