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!
01.
Form Type Class
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!
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
}
}
81 Comments
Not to be a whiner but I notice this is pretty dated. WIll there be an update, or are forms really too 2016? :-)
Hey davidmintz
Not sure about eta on new forms or even will be it released or no, however from my point of view nothing changed, everything mentioned here can be used in newer Symfony version, so the main ideas are still relevant
Cheers
how about adding comments ? with AJAX :D
Hey Ad F.!
That's an interesting idea! In theory, it's not really different than a normal form submit, but perhaps it's different enough that it's worth covering. Is there any part of this specifically that you're most interested in?
Cheers!
well, you have covered pretty much everything except comments, or how to add comments to an article as logged in user via ajax, or APi
when adding a comment, the author of post should be notified ... more complex stuff ...
or working with multiple forms.
subscribe to a topic & when someone post a new article on space bar, those subscribers will get a email notification...
there are plenty of stuff
will be a great idea to add those features to the course
Yeah that would be great!
If using Symfony > 4 (7 is the current), make sure to use
$formand not$form->createView()when rendering:instead of
Otherwise form errors are not displayed.
Hope this saves fellow devs who also do not read the manual, the time I wasted.
Reference: https://symfony.com/doc/current/forms.html#rendering-forms
Hey Radu,
Welcome to the club! ;) - Yea, that's a change in a recent Symfony version, you don't have to call
createView()anymoreCheers!
Others have already mentioned it and its the same for me: the setup is not easy since so many things are outdated now...
After having to install an old PHP version and an outdated composer version, I had problems connecting to the database. The fix was to explicitly set
mysql_native_passwordas the authentication method in mysql.This is the first lesson in this course and having to fight with the setup really takes away a lot of motivation. Forms are an important component so please, update this course to make setup easier.
Hey Mimimi,
Sorry for the inconvenience! We're working on adding more Symfony 7 related tutorials, including one about Symfony forms. You're right, this code is kinda outdated already because this course requires PHP 7 and will not work on PHP 8 out of the box. Unfortunately, we can't update the code because it will not match the video then, but we're working on releasing an updated course about this topic. No estimations yet, but first, we will release a tutorial about Security and next, we will plan another one about Symfony Forms. Thanks for your patience!
And I hope the initial setup was the hardest part of it! When you get it working, it should be easier to follow this tutorial. But if you encounter any issues while following this course - feel free to leave a question in the comments section below the video and our support team will help you!
Cheers!
Thanks for the quick reply, Victor! Yes after the setup the content is great, as always :) Looking forward to the updated tutorial!
Hey Mimimi,
Great, thanks for confirming it's smoother to follow the course after a tricky setup.
Sorry for the inconvenience and your patience! We're doing our best to speed up more Sf 7-related content ;)
Cheers!
The code code requires php 7.1, and, as in all 7.1 courses, I cannot run composer because the latest version does not support PHP <7.2.5, and I do not want to downgrade/upgrade composer all of the time.
Do you know of a workaround? I have PHP 7.1, my problem is with composer.
TIA,
François
Hey @Francois!
Yea, this tutorial - even if the contents are still valid - is showing its age BIG time. But, have you tried the code with PHP 7.2 or 7.3? Iirc (and this shows when you hover over the code download), this tutorial requires
^7.1.3- which means 7.1.3 or higher but less than 8. So 7.2, 7.3 should work. But let me know if you run into any issus.Cheers!
Thanks, using the 7.2 binary did the trick.
Hi
Very useful code. However, Will the course code works with Symfony 6 and PHP 8 ? Anyone tested that?
Regards
Hey t5810,
This course is based on Symfony 4. but the concepts we're teaching in this course are still valid for today. So, you can follow this course on a fresh Symfony 6 and PHP 8 for sure. You may notice some little differences but they all should be covered in the video and in the scripts with notes. However, in case you are stuck somewhere following this course on Symfony 6 - let us know in the comments below the video and our support team will help you ;)
Cheers!
Hi Victor
Thanks for your prompt and detailed answer. Today I make several attempts to amend the composer.json in attempt to install Symfony 6.2, but all my attempts failed.
Which are the steps that you would follow when you would like to watch old course but using Symfony 6? I would really like to learn this process, since all those dependencies when they start to hit your console with errors, one feel fairly helpless. If that is too much for explaining, can you point me to some resource where I can learn this technique?
On the end, it would be great if you symfony casts can have 2 json file in version tabs in older courses, one the original, and other with the latest version.
Regards
Hey t5810,
Oh, that's a bit tricky to upgrade old courses. The ideal would be to upgrade the old course by yourself... but upgrading major version, i.e. from 5 -> 6 may require a lot of work. Most probably it won't work after just installing the proper Symfony-6 dependencies because you also have to upgrade recipes, change BC breaks, etc.
So, the easiest would be to download a fresh new empty Symfony version from the official website, e.i following the steps from here: https://symfony.com/download - and then try to apply the changes you see from the video. You may need some prerequisites - like controller/template - but you can steal some code from the course. It's still not perfect as requires from you more changes, but that's how it is possible to follow it.
Or, as the 3rd option, you could try to follow the course on your own personal project, but it also may require some additional steps, like fetching some code from the course project.
I hope this helps!
Cheers!
Hi Victor
Thanks for the useful ideas, I will see what it suites me best. Maybe I will first watch the course as is, and then I will try to implement the knowledge on some my mini demo project.
Thanks.
Hey t5810,
Yeah, this is also a good idea! When you finished the whole course - you will have a lot of ideas about what exactly and where you could apply in your own project, so it's not the perfect user experience we would like our customers to have while watching our courses... but definitely a valid option for older tutorials.
Cheers!
Hey,
when i try to load then new article i get this error message,
But it's there. What could be the reason? Thanks in advance.
Jimmy
Hey Jimmy!
Look closer to the namespace in the error message :) It seems like you missed to use the correct namespace somewhere, I suppose you form type is located inside
src/Form/? So, its namespace should beApp\Form\ArticleFormType- check that file first, and make sure its namespace matches the file structure. Then, check the controller where you use that form - I bet it misses the use statement :)Cheers!
Hey,
thank you. I've already found it on my own. But i will have one question or more in the future 😊.
Cheers, Jimmy
Hey Jimmy,
Awesome, well done! Feel free to update or delete your comments that were not answered by the support yet in the future if it's not relevant anymore - it will unload our support a bit :)
Cheers!
Hello, I would like to go throw this course but in initial stage I have some issue with symfony 4 and php version which aren't compatible. Is the any solution for it?
Hey Alexander!
What problem exactly do you have? We would be happy to help you with it. Please, notice that this course isn't compatible with PHP 8, so if you want to follow this - there're a few options:
- Downgrade your PHP version to at least 7.4 (or you can install it additionally, like having both PHP 7.4 and 8.x versions. Or also there's an opportunity to use Docker as well)
- Or download the course code and try to upgrade it to the PHP version you're using locally. But it might require some extra work from you unfortunately. Though we have a course about upgrading that might help you with this: https://symfonycasts.com/sc...
- Or, you can download a fresh new Symfony version instead and try to apply all the changes we're showing in this course on it. It might be easier than the previous option, because you won't need to deal with upgrading at all. And of course, if you get stuck following this course on a newer Symfony version - let us know in the comments below the video and we will definitely help you to go further!
Cheers!
Hey Victor
I'll try to downgrade PHP version on additional laptop to 7.1
Thanks for fast reply)
Hey Alexander,
Great! Though I would suggest to upgrade to 7.4 instead - it should fit well, and not that ancient as 7.1 ;)
Cheers!
Downloaded project folder. Followed README, installed all accordingly: PHP72 version:
TypeError
array_key_exists(): Argument #2 ($array) must be of type array, Symfony\Component\Debug\Exception\FlattenException given
Hi, there , I have a question, I have multiple connections to different entities manager, and I want to create a form without using the default EM, by the way in the form I want to create a Combo box with Entity that is in an other EM, but I have this error when I'm creating the view of the form "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'em_default.table_in_other_em' doesn't exist"
Hey Francisco,
Could you show the code how you add that Combo box to your form type? Well, EntityType has a specific field called "em": https://symfony.com/doc/cur... - you can specify what entity manager to use. Or, you can easily inject any entity manager to the form type and use it inside.
I hope this helps!
Cheers!
Hi, victor I have injected the entity manager to the form, but I still have problems with the create view.
This is my code:
doctrine.yml
Controller:
Form:
<blockquote>ERROR: "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'em_default.Entity1_of_conn5' doesn't exist"</blockquote>
Hey Francisco,
Thanks for sharing more data with me! First of all, the line "$this->class = $this->em->getRepository(Entity1_of_conn5::class);" I'd recommend to rename to "$this->conn5Repository = $this->em->getRepository(Entity1_of_conn5::class);" or something like this as getRepository() method clearly returns the repository to you.
And once again, as I mentioned in my previous comment, you have to set that "em" option for your EntityType, I still don't see you did it. I.e. change to something like this:
I hope it helps :)
Cheers!
Thank you for your help victor it works!
Hey Francisco,
Awesome! Thank you for confirming it works :)
Cheers!
I'm building an application with MySql that have big entity, with about ~ 200 fields, and I'm looking for some best practices to handle this.
And I expect to have at least 5000 records in entity per year.
Which is the best way to improve performance in my case? Keep all fields in the same entity, or split in two or more with a relation OneToOne?
I know that it depends in how I will work with this data, so i'm asking in a general way situation.
Hey Dmitriy,
It's really hard to answer, I'd recommend you to grab Blackfire.io profile tool and check your current performance. If it works well for you and you're happy with times it shows - great, nothing should be complicated probably. But you're right, it depends on how you use those data. If you almost always need all those fields - it probably better to keep them in the same entity instead of making OneToOne relations, as you will avoid joins in this case.
But if you're just looking for a way of "group" fields together - you can think about moving them to traits, like different traits would contains some fields that are logically grouped. This way you will group them, so probably it would be easier for you to work with all those fields, but you still will have them on the same entity.
But about performance - it is really difficult to say at the first glance, and very easy to check with profiling tools as Blackfire.io that I would recommend you.
I hope this helps!
Cheers!
What was the tip for the rocket image ?
Hey Joseph T.
If you work with PhpStorm, there are plugins that you can use to add emojis into your templates. Here you can see the full list of emojis https://www.w3schools.com/c...
Cheers!
Couse code does not work "flawlessly" with PHP 7.4+ a lot of dependencies have: PHP Deprecated: Array and string offset access syntax with curly braces is deprecated
And of course: "Composer Update" fixed the problem 🤦🏼♂️
Hey CISVHenriksen
Honestly we don't recommend to run
composer updateon course code, because it can bring unexpected result or code behaviour. But sometimes we do update internal dependencies when something became incompatible. It's a very complex process and that is why deprecations are not the reason for complex updates.If you have something really not working in course code, please report us back with details.
Cheers!
Hi, I have an interesting problem with this. For another project it was not an issue but downloading this course files there is an issue with the form. When the form is rendered, there is a mistake that <div id="article_form"> renders as <divid="article_form">. Therefore, broking the whole HTML code. The code is just as downloaded from your course. Do you have an idea why is it so?
Hello Mārtiņš C.
Thanks for reporting this issue, it was just fixed, so you only need to re-download course code and continue crushing this course! If you are interested it was caused by twig library version.
Cheers!
Thanks!
Hey Mārtiņš C.
Just to clarify do you use PHP 7.4?
Cheers!
I have a problem launching project. Opening web I get red Symfony error window: "PDOException >PDOException> DriverException", "An exception occurred in driver: could not find driver". In server terminal i see: many lines with PHP Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/.../code-symfony-forms/start/vendor/michelf/php-markdown/Michelf/Markdown.php on line [955...1801] and MarkdownExtra.php line [215...1469] and red error: 127.0.0.1:59528 [500]: GET /
It seems you need to include PDO driver in php.ini.
"Houston: no signs of life"
Start the conversation!