If the reader is coming from the table world, you should know how to change the template provided by the third party bundle by overloading the template. Here we will reload the user login page as a job left to everyone, we first to reload the registration page, but in order to provide fresh knowledge points, we this time in addition to decorate the registration page, but also request to the registration page to provide verification code.
For the master of my collection of bundles, naturally, the recommended CAPTCHA-related Bundle:gregwarcaptchabundle
Install Bundles as always
12 |
$ composer require Gregwar/captcha-bundle |
Register bundles as always
12345678910 |
//app/appkernel.phppublic function registerbundles() { $bundles = array( // ... New Gregwar\captchabundle\gregwarcaptchabundle(), /c7> );} |
Well, the preparations are over.
Heavy-duty Fosuserbundle Registrationformtype
Fosuserbundle supports the use of other registration forms. Just a simple configuration can be
1234567 |
# app/config/config.yml fos_user: # ... Registration: form: type: app_reg |
However, we have not implemented the current type designation app_reg
, and we should create this form_type. If you chew on an official document, you should know that defining a form_type requires defining a FormType class before defining it as a service, and the alias of the service must be consistent with what the form getName
method returns.
Define the class first:
12345678910111213141516171819202122232425 |
<? PHP //src/appbundle/form/type/regtype.phpnamespace appbundle\Form\Type; use Symfony\Component\Form\formbuilderinterface; use FOS\userbundle\Form\Type\registrationformtype; class regtype extends registrationformtype {Public function buildform(formbuilderinterface $Builder , array $options) { Parent::buildform($builder, $options); $builder,add(' captcha ', ' Captcha ', [ ' mapped ' => false, ]); }Public function getName() { return ' App_reg '; }} |
Then the service:
123456789101112 |
# app/config/services.ymlServices: # ... app. Form. Type. Reg: class: appbundle\Form\Type\regtype /c4> arguments: - %fos_user. Model. User. Class% Tags: - name: form. Type alias: app_reg |
Let's visit /register
the page and see a form field with a captcha, even though the whole form is ugly enough to be a friend ...
Find the template that should be overloaded according to the way the table world says
To be Continued ...
Since this tutorial was created on April 9, I've been trying to end this series as soon as possible, offering a perfect ending for everyone, but not knowing how to do it and not knowing what features to add to our small project. Recently work is also busy, overtime is the norm, has been dragged, but some things if he has been dragged, may be really left behind, it is better to be more carefree.
Today I think of how this series should also have a statement, my intention is to forcibly end this tutorial, but the exploration and sharing about Symfony2 will continue. If you're not in the best interest, you can continue to follow my other posts in posts. This tutorial is written for the students just learning Symfony2, if you have read, you should know the approximate usage of Symfony2. Later I will write some independent articles to introduce the various development solutions provided by Symfony2 to you.
Thank you
Symfony2 Framework Practical course--sixth day #alt: verification Code