This course is archived!

>

Course Overview

Question and Answer Day: March 27th, 2013

  • 3554 students
  • EN Captions
  • EN Script
  • Certificate of Completion

Your Guides

About this course

Woh! KnpUniversity Question & Answer Day is March 27th, 2013!

Submit all your Symfony, Behat and PHP questions by March 26th, 2013 and we'll answer them. We're calling it KnpU Question/Answer Day - we're finally shutting up and doing the listening!

140 Comments

Sort By
Login or Register to join the conversation
Default user avatar kendoctor 5 years ago

well done.

42 | Reply |
Default user avatar Carlo Maria Piacenti 5 years ago

Thanks for the useful lesson. I've been searching the web for days to discover some more deep explanation of the topic, and finally found this one. Your info & examples really pushed me forward... thanks a lot!

30 | Reply |
Default user avatar Sergey Vershinin 5 years ago

Hello!

i have a difficult question about extra routing and i hope that You help me to choose a right way..

In our project we have a difficult routing rule.

In example, we have a base domain "superdomain". Our project must "understand" {region}.superdomain.{zone} host - i guess it`s solved by

_acme_demo:

resource: "@AcmeDemoBundle/Resources/config/routing.yml"

host: "{region}.superdomain.{zone}"

defaults: {region: vrn, zone: dev }

$region = $this->getRequest()->get('region');

$zone = $this->getRequest()->get('zone');

{{ url('_welcome', {region: 'kharkov', zone: 'com'}) }}

It works, but we also have a special promo sites and they have a own routing.

Promo sites host could be "{megapromo}.superdomain.{zone}" or "{megapromo}.{zone}"

and these promo sites must use a special routing in PromoBundle ..

so i can`t understand How handle and process special promo sites routing :(

i guess i must extend a Routing object or UrlMatcher or Dumper, but i have no idea how..

p.s. sorry for my English

22 | Reply |
Default user avatar SimonSimCity 5 years ago

Just to complete this ... I found the answer to the last question:

It takes thousands of dinosaurs millions of years......cos they have to evolve deposable thumbs so that they can grip the bulb to screw it in.

5 | Reply |
Default user avatar pieter lelaona 5 years ago

been very difficult to find examples of applications and explanations actually implement symfony2 framework. eg
1. how to create a complete multi-user management with an ACL that retrieves data from a database and integrated with the menus link, filter data, and dynamic multi-role and permission
2. best project skeleton in symfony2 framework.
3. create a dynamic system such as the theme cms wordpress, drupal, joomla, etc

above is a small part of many people, especially in my country (Indonesia) who want to learn more to sysmfony2 framework.
what do you think??
sorry about my english

3 | Reply |

Wow! This is a great big question, and we'll do our best to answer it on Monday (April 1) :)

| Reply |

hi thanks.. i will wait the answer.. :)

| Reply |

Woo!! Your answer is live: http://knpuniversity.com/sc...

| Reply |
Default user avatar pieter lelaona KnpUniversity 5 years ago

greate... thank you soo much..

| Reply |
Default user avatar Gerard Araujo 5 years ago

What is a typical/ideal bundle and firewall structure for symfony 2 for a project with the following basic requirements

- frontend [ public ]
- frontend [ for logged in ]
- backend [ for admin ]
... and a few entities that are owned by users like
books, media, category...

1. assuming i use fosuserbundle, should i have at least 2 bundles ( 1 for fos extension ) ? more than 2? or only 1?
what advantage/disadvantage to i get with each option?

2. is one firewall sufficient? what if i need different login
routes?

3. how many dinosaurs does it take to replace a lightbulb?

3 | Reply |

Awesome questions! We have some field research to do on #3 this weekend and your answers will be posted on Tuesday, April 2nd :)

| Reply |

"...don’t fool yourself by thinking that you can separate your features into totally standalone, decoupled bundles." I fooled myself once and regret it almost daily...

3 | Reply |

Sounds good. about question 1. by fos extension, i mean fosuserbundle :)

| Reply |
Default user avatar Gerard Araujo Gerard Araujo 5 years ago edited

@twitter-429749331 , I'm really looking forward to the answers for this, thanks.

| Reply |

And here it is! http://knpuniversity.com/sc...

Cheers!

| Reply |

Thanks, well played on question 3 :)

| Reply |

As Symfony becomes more powerful and scalable, is that at the expense of being less useful for small rapid developments - given the large number of dependencies and configuration required on each project? (Setting up user login, media management, content repository, Gaufrette, admin generator, etc.).

1 | Reply |
Default user avatar KnpUniversity Andy 5 years ago edited

Happy Monday @acd95cccc60a3bceabbb74110dd2f3fa ! Your question has an answer: http://bit.ly/sf2-RAD

1 | Reply |
Default user avatar KnpUniversity Andy 5 years ago

Thanks for the RAD question to KnpU Q&A! We'll get your answer posted on Monday (April 1) :)

| Reply |
Default user avatar Audrius 5 years ago

As Symfony is Request/Response rather than MVC framework what is best (business/developer ratio) structure to implement model layer into Symfony applications.

Lets say you have a lot of business logic inside your application, or porting normal MVC application to Symfony, what is best way (in your opinion) to organize structure for applications? All business logic goes into services? Fat controllers? Any other solutions?

@shivas80

1 | Reply |

Hey Audrius!

I know we pinged you on Twitter, but for reference - your answer is here: http://knpuniversity.com/sc...

Cheers!

| Reply |
Default user avatar spolischook 5 years ago

How to connect Symfony2 project with Behat and Sahi to Travis Ci @SPolischook

1 | Reply |

Awesome question! I wish someone had answered this for us a few months ago ;). Hopefully this at least helps you out a bit!

http://knpuniversity.com/sc...

Thanks for your question!

1 | Reply |

Thanks Rayan, It's awesome, and its work!!! Only I add:
- cp app/config/parameters.yml.dist app/config/parameters.yml
All work like a charm!

| Reply |
Default user avatar Dimka Mo 5 years ago

How to hide the pattern for route like "param" in parameters.yml? My goal looks like: i have some line in parameters.yml myurl = /are/you/a/robot/ which were in routing.yml something like this: pattern (path soon): %myurl% I need to hide my url pattern from public, how can i do this? Thanks! @dimka_mo

1 | Reply |

Hey Dimka!

I want to make sure I'm understanding correctly :). Does your situation go beyond using a parameter as the value of the route pattern? For example, assuming you have `myurl` in `parameters.yml` (like you've written), then the following is valid in a routing.yml file:

parameter_test:
path: %myurl%
defaults: { _controller: MyBundle:Default:index }

Let me know if there's something beyond this :). If it's just this, that's all you need! If there's something else, we're happy to answer it.

Cheers!

| Reply |

Thanks for help! That's it!

| Reply |

And explained in infinitely more detail just for fun :)

http://knpuniversity.com/sc...

Thanks for your question!

| Reply |
Default user avatar Yusuf 5 years ago

I got this error, anybody can help ?

ContextErrorException:
Catchable Fatal Error: Argument 2 passed to XX\XXXBundle\EventListener\CurrentSiteListener::__construct() must
be an instance of Doctrine\ORM\EntityManager, none given, called in
/var/www/html/XPROJECT/app/cache/dev/appDevDebugProjectContainer.php on
line 642 and defined in
/var/www/html/XPROJECT/src/KW/CoffeeHRBundle/EventListener/CurrentSiteListener.php
line 16

1 | Reply |

Hi Yusuf!

This looks like a problem with your service configuration (i.e. services.yml). It looks like you need to pass the entity manager as your second argument. You're doing something a bit different than what we show, but it'll look something like this:

https://gist.github.com/wea...

Cheers!

| Reply |

thanks, it solved now

| Reply |
Dung L. avatar Dung L. 4 years ago

Hello to all,

In symfony4, I would like to implement an image slider/photo gallery/carousel example: https://calgaryhomes.ca/lis... but Googling does not return much helpful information or even better is tutorials on this topic. Can you please point to me to some good source to learn how to do this? much appreciate any suggestion!

| Reply |

Hey Dung,

Unfortunately, we don't have any courses on SymfonyCasts about something similar. Though, most of the time docs are pretty good for such libraries. I'd recommend to find a popular one on GitHub, you can use their search, and look if it has some good docs that explain how to implement it. Or, some of them might have some kind of demo page, where you can just watch source code and copy/paste the same HTML structure, etc.

For example, here's some most popular JS carousel libraries on GitHub: https://github.com/search?l...

Feel free to tweak the search term or sorting to get more relevant results for you.

I hope this helps!

Cheers!

| Reply |

Thank you, it is good to know. I used https://getbootstrap.com/do... and it works very nice and so easy to implement to twig. This works well partly because Bootstrap 4 is already loaded in the project.

| Reply |

Hallo there!

Post your questions here - I'm looking forward to seeing what you can all come up with!

Cheers!

| Reply |
Default user avatar John Kary 5 years ago

When conducting trainings, what is the biggest challenges new Symfony2 developers faced, and how have you helped them overcome them?

| Reply |
Default user avatar cordoval 5 years ago

I am passing this one from my friends at my job :), i am needing to set a default type of sorting on knp paginator, I had to hack $this->query->set('key_name', $key_value); and also set with $_GET['key_name'] = $key_value; for it to actually work. Is there a non hacky way to do this? @cordoval

| Reply |
Default user avatar cordoval 5 years ago

how to configure monolog so to send an email not only on exception 500 but also on any error and at the same time show the overridden exceptions as in the cookbook to show 404 page on errors on production. So two things in one at the same time. @cordoval

| Reply |
Default user avatar cordoval 5 years ago

regarding behat do you really recommend the page object pattern approach fully on a big application?

| Reply |

@ab2a6b877dd41427c660a3d6a170cc71 Hey buddy! Can you elaborate? I assume you're talking about the `$session->getPage()` page object, correct? What do you mean exactly by the page object pattern approach?

Cheers!

| Reply |

The "Page" model of working with Behat is very interesting, and anyone who is new to it should check it out for him/herself via the brand new "Page Object Extension": http://extensions.behat.org...

I have no big opinion on this - it looks very nice, and Jakub Zalas (the guy who wrote it) is very smart! So, check it out!

| Reply |

is there a sane way with the form layer and a custom form type to determine if a field is required based on the actual content that is bound to it? i hacked up this gist which i hope shows the idea:
https://gist.github.com/dbu...

thanks, @dbu

| Reply |

This is actually really, really interesting question :). But, I wanted to find out your end goal. Of course the Form::isRequired can be used anyway you want, but out-of-the box, it's only used to set the "required" FormView variable and in the logic for a field's "empty_data". I know you're not worried about the latter, since in the event listener callback, you're already assuming that there's data (so obviously it was never empty). So then, what is the true reason behind wanting to set the required option dynamically?

Let me know - this has been a fun one to dig around in :).

Cheers!

| Reply |

uh, i notice that the gist is incomplete. i am extending the FileType form element. when creating an entity with a file in it, i want the file to be required. when editing that entity, it already has the file as it was required when creating it. the way file upload and forms work, it won't see the file is already there. if the form element is required, the user would have to re-upload the file each time he changes anything in the form. so the idea is to force uploading the image file for the create case, but not for the edit case. and i want to do this in a form type, not manually where i build the form. (the reason for that is here: https://github.com/symfony-..., but in general i think it would be more elegant if the form element would handle this.)

| Reply |

And another question about the form layer: When i provide a custom type in a bundle, is there a way to automatically register the twig template for the widget, or is the only way to add it to the list of form templates in the application configuration?
thanks, @dbu

| Reply |

@twitter-12162742 I think the answer to this is unfortunately easy: it's not possible :). Ultimately your resource needs to make it into TwigRendererEngine as either a "defaultTheme" (and array of these are passed to the constructor) or as a "theme" (via setTheme, which is specific to a specific FormView instance).

The "defaultThemes" passed to the constructor are filled in by a `twig.form.resources` parameter, which is set in TwigExtension from the `twig` form resources stuff. So, there's basically no hook point into any of this, short of adding a compiler pass that mutates this argument after the container is built. So yes, I suppose it *is* possible, though it may be a question of whether this is too heavy-handed or not :).

Cheers!

| Reply |
Default user avatar ThiagoKrug 5 years ago

Hi, I am reusing one form but I have one specific controller action that I need remove one field form, How can I do it without creating new form? Thanks!

| Reply |
Default user avatar KnpUniversity ThiagoKrug 5 years ago

We love form questions! And your answer will be posted on Monday (April 1st)!

| Reply |
Default user avatar KnpUniversity ThiagoKrug 5 years ago edited

Hello @0f36cd3c7e16a42dc93feceadc339c98 ! No fooling, your answer has arrived! http://bit.ly/Xm5ZAS

| Reply |
Default user avatar Rafael 5 years ago

Hi, I am coding one events calendar, It is adding events however how can I validate if the event I am placing does not conflict time with another one event? I was thinking about entity validadation callback but should it be in entity? or repository? I don't want to lose symfony validation that display errors on the forms.

| Reply |

Delete comment?

Share this comment

astronaut with balloons in space

"Houston: no signs of life"
Start the conversation!