Chapters
41 Chapters
|
4:45:40
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
30.
The buildView() Method
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
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.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.2
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knplabs/knp-paginator-bundle": "^2.7", // v2.8.0
"knplabs/knp-time-bundle": "^1.8", // 1.8.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.0.0
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.0
"sensio/framework-extra-bundle": "^5.1", // v5.2.1
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.1.6
"symfony/cache": "^3.3|^4.0", // v4.1.6
"symfony/console": "^4.0", // v4.1.6
"symfony/flex": "^1.0", // v1.21.6
"symfony/form": "^4.0", // v4.1.6
"symfony/framework-bundle": "^4.0", // v4.1.6
"symfony/property-access": "^3.3|^4.0", // v4.1.6
"symfony/property-info": "^3.3|^4.0", // v4.1.6
"symfony/security-bundle": "^4.0", // v4.1.6
"symfony/serializer": "^3.3|^4.0", // v4.1.6
"symfony/twig-bundle": "^4.0", // v4.1.6
"symfony/validator": "^4.0", // v4.1.6
"symfony/web-server-bundle": "^4.0", // v4.1.6
"symfony/yaml": "^4.0", // v4.1.6
"twig/extensions": "^1.5" // v1.5.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.7
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/debug-bundle": "^3.3|^4.0", // v4.1.6
"symfony/dotenv": "^4.0", // v4.1.6
"symfony/maker-bundle": "^1.0", // v1.8.0
"symfony/monolog-bundle": "^3.0", // v3.3.0
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.1.6
"symfony/stopwatch": "^3.3|^4.0", // v4.1.6
"symfony/var-dumper": "^3.3|^4.0", // v4.1.6
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.1.6
}
}
18 Comments
Not sure why but adding the `javascripts` block to the edit or new template make the debug bar disappear into thin air
Console shows the following error:
```js
Uncaught ReferenceError: Sfjs is not defined
at new:89:44359
at new:89:44392
```
Hey danresmejia
Is it possible you forgot to call the parent?
{{ parent() }}Cheers!
On the Edit page I am getting this error: Can only be used with user objects.
\Form\DataTransformer\FormToUserTransformer.php (line 32)
`if (!$value instanceof User) {
}`
Hey Farry7,
Check your FormToUserTransformer, you wether apply that data transformer to a wrong entity, or it does not allow null probably. To know for sure, try to debug the $value, you can add "dd($value);" before throwing the exception - that will give you some hint about the value of that variable. Or maybe you just forgot to use the correct namespace for your User entity in FormToUserTransformer :)
I hope this helps!
Cheers!
Hi,
when i try to insert any parameter (for exemple i need RouterInterface $router) in the Article Constructor (my Article is Gruppi), i get the message
Too few arguments to function App\Form\Form\Gruppi\GruppiType::__construct(), 0 passed in C:\Users\Giacomo\Documents\GitHub\fgcweb\vendor\symfony\form\FormRegistry.php on line 91 and exactly 2 expected
I think this come from the controller's line:
$form = $this->createForm(GruppiType::class, $gr);
Now, there is a way to use RouterInterface from inside Gruppi without get that error, so i can set:
'data-autocomplete-url' => $this->router->generate('get_group_fields');
without the need to create a new form and use it in Gruppi's buildForm?
If i instance
$this->router = RouterInterface::class; iinside the constructor, the error is solved but i get:
Call to a member function generate() on string
in
$attr['data-autocomplete-url'] = $this->router->generate('get_group_fields')Reading docs i did:
`
`
but it's very verbose and the output is:
data-autocomplete-url="//gr/utility/gruppi"
Any suggestion for a shorted and correct solution?
Thanks a lot!
Hey Giacomo V.
Which version of Symfony are you using? If you are using auto-wire and auto-configure features, then you should be able to just type-hint your services in the Form class and Symfony should do the rest (https://symfony.com/doc/cur... ). If not, you will have to define such Form class as a service
Cheers!
Hello there ,
This error occurs when saving the form.
Error: <blockquote>The choices "single" do not exist in the choice list.</blockquote>
I don't understand why I can't define the choices in the buildView method
Where can I do it? So that on the parent form I don't have to do it. Choices will be generated based on an option in the parent form called "entity_name"
Hey Jose carlos C.
Give it a try defining the choices option at the
buildFormmethodCheers!
How? I've tried a thousand ways in the
buildFormand I couldn't.Ohh I see now why it's difficult, you are extending from
ChoiceTypeand no adding any new fields. Hmm, what you are doing seems OK but since you are relying on the "field variables" I think you need to create aChoiceViewitem per each option and put them onto an array. Check the "choices" definition here:https://symfony.com/doc/current/reference/forms/types/choice.html#field-variablesI haven't done that before so I might be wrong
Another thing you can try is to define the "choices" inside
configureOptions()method as you did to: expanded, multiple, etcIn configureOptions this is not possible, because the list depends on a newly defined option called 'entity_name'.
This is the parent form field:
Have you tried adding the choices in there?
I want to do it without having to add it to the parent form, as I said before.
Yeea, it's kind of the diffcult what you are trying to achieve. Did you try to create your own
ChoiceViewlist and use it in thebuildView()method? If that doesn't work I think the answer to your problem may be managed via FormEvents https://symfony.com/doc/current/form/events.htmlBTW, when I am trying to put in twig this
`
`
I am getting broken autocomplete. I mean it won't work. Still I have correctly appended the needed class...
Hey MASQUERADE promotion!
Do you get any JavaScript errors? And when you inspect your HTML, do you see the class being printed on your element? Finally, in our code, we added the class
js-user-autocomplete- but it looks like you're adding a class calledthe-author- is that in purpose?Cheers!
thanks
yeah, you are correct.
"Houston: no signs of life"
Start the conversation!