Symfony controller to register and activate users
up vote
0
down vote
favorite
I've been in an interview some time ago. They objected my Symfony API code with following line:
Too much code in controller actions. Can be moved to services to keep
the business logic apart from the representation. Also violating
single responsibility.
I have been trying to improve my code since then. Trying to bring SOLID in my code design and writing services for different tasks.
Now I am working on an app where I have written a controller. It still looks bulky even though it is just using services.
There are two methods:
- Register, to register user, add user to database and send activation code to their email
- Activate, get activation code from URL and activate the user or show error.
I want to know if there is any room for improvement here.
namespace AppController;
use AppEntityUser;
use AppFormUserType;
use AppSerializerFormErrorSerializer;
use AppUtilsActivationKeyManager;
use DoctrineORMEntityManagerInterface;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationJsonResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingGeneratorUrlGenerator;
use SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface;
use SymfonyComponentTranslationTranslatorInterface;
/**
* Class AuthController
* @package AppController
*/
class AuthController extends AbstractController
{
/**
* @param Request $request
* @param TranslatorInterface $translator
* @param EntityManagerInterface $em
* @param UserPasswordEncoderInterface $encoder
* @param FormErrorSerializer $formErrorSerializer
* @param ActivationKeyManager $activationKeyManager
* @param Swift_Mailer $mailer
* @return JsonResponse
*/
public function register(
Request $request,
TranslatorInterface $translator,
EntityManagerInterface $em,
UserPasswordEncoderInterface $encoder,
FormErrorSerializer $formErrorSerializer,
ActivationKeyManager $activationKeyManager,
Swift_Mailer $mailer
) : JsonResponse {
$form = $this->createForm(UserType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/**
* @var User $user
*/
$user = $form->getData();
$encoded = $encoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($encoded);
$em->persist( $user );
$em->flush();
$activationLink = $this->generateUrl(
'activate',
[
'code' => $activationKeyManager->getKey($user),
'user' => $user->getId()
],
UrlGenerator::ABSOLUTE_URL
);
$message = (new Swift_Message($translator->trans('Activate your account')))
->setFrom($this->getParameter('admin_email'))
->setTo($user->getEmail())
->setBody(
$this->renderView(
'emails/registration.txt.twig',
['activationLink' => $activationLink]
),
'text/plain'
);
$mailer->send($message);
return new JsonResponse(['status' => 'success' , 'details' => $translator->trans('User has been created successfully.')]);
}
return new JsonResponse(['status' => 'error' , 'details' => $formErrorSerializer->convertFormToArray($form)], Response::HTTP_BAD_REQUEST);
}
/**
* @param Request $request
* @param TranslatorInterface $translator
* @param EntityManagerInterface $em
* @param ActivationKeyManager $activationKeyManager
* @return JsonResponse
*/
public function activate(
Request $request,
TranslatorInterface $translator,
EntityManagerInterface $em,
ActivationKeyManager $activationKeyManager
) {
$user_id = $request->get('user');
$activationCode = $request->get('code');
if (!$user_id || !$activationCode) {
return $this->sendInvalidActionCodeResponse($translator);
}
/**
* @var User $user
*/
$user = $em->getRepository(User::class)->find($user_id);
if (!$user) {
return $this->sendInvalidActionCodeResponse($translator);
}
if ($activationKeyManager->keyIsValid($user, $activationCode)) {
$user->setActive(true);
$em->flush($user);
return new JsonResponse(['status' => 'success' , 'details' => $translator->trans('Your account has been activated.')]);
} else {
return $this->sendInvalidActionCodeResponse($translator);
}
}
/**
* @param TranslatorInterface $translator
* @return JsonResponse
*/
private function sendInvalidActionCodeResponse(TranslatorInterface $translator)
{
return new JsonResponse(['status' => 'error' , 'details' => $translator->trans('The provided activation code is not valid.')], Response::HTTP_BAD_REQUEST);
}
}
php interview-questions mvc controller symfony2
New contributor
EresDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 1 more comment
up vote
0
down vote
favorite
I've been in an interview some time ago. They objected my Symfony API code with following line:
Too much code in controller actions. Can be moved to services to keep
the business logic apart from the representation. Also violating
single responsibility.
I have been trying to improve my code since then. Trying to bring SOLID in my code design and writing services for different tasks.
Now I am working on an app where I have written a controller. It still looks bulky even though it is just using services.
There are two methods:
- Register, to register user, add user to database and send activation code to their email
- Activate, get activation code from URL and activate the user or show error.
I want to know if there is any room for improvement here.
namespace AppController;
use AppEntityUser;
use AppFormUserType;
use AppSerializerFormErrorSerializer;
use AppUtilsActivationKeyManager;
use DoctrineORMEntityManagerInterface;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationJsonResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingGeneratorUrlGenerator;
use SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface;
use SymfonyComponentTranslationTranslatorInterface;
/**
* Class AuthController
* @package AppController
*/
class AuthController extends AbstractController
{
/**
* @param Request $request
* @param TranslatorInterface $translator
* @param EntityManagerInterface $em
* @param UserPasswordEncoderInterface $encoder
* @param FormErrorSerializer $formErrorSerializer
* @param ActivationKeyManager $activationKeyManager
* @param Swift_Mailer $mailer
* @return JsonResponse
*/
public function register(
Request $request,
TranslatorInterface $translator,
EntityManagerInterface $em,
UserPasswordEncoderInterface $encoder,
FormErrorSerializer $formErrorSerializer,
ActivationKeyManager $activationKeyManager,
Swift_Mailer $mailer
) : JsonResponse {
$form = $this->createForm(UserType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/**
* @var User $user
*/
$user = $form->getData();
$encoded = $encoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($encoded);
$em->persist( $user );
$em->flush();
$activationLink = $this->generateUrl(
'activate',
[
'code' => $activationKeyManager->getKey($user),
'user' => $user->getId()
],
UrlGenerator::ABSOLUTE_URL
);
$message = (new Swift_Message($translator->trans('Activate your account')))
->setFrom($this->getParameter('admin_email'))
->setTo($user->getEmail())
->setBody(
$this->renderView(
'emails/registration.txt.twig',
['activationLink' => $activationLink]
),
'text/plain'
);
$mailer->send($message);
return new JsonResponse(['status' => 'success' , 'details' => $translator->trans('User has been created successfully.')]);
}
return new JsonResponse(['status' => 'error' , 'details' => $formErrorSerializer->convertFormToArray($form)], Response::HTTP_BAD_REQUEST);
}
/**
* @param Request $request
* @param TranslatorInterface $translator
* @param EntityManagerInterface $em
* @param ActivationKeyManager $activationKeyManager
* @return JsonResponse
*/
public function activate(
Request $request,
TranslatorInterface $translator,
EntityManagerInterface $em,
ActivationKeyManager $activationKeyManager
) {
$user_id = $request->get('user');
$activationCode = $request->get('code');
if (!$user_id || !$activationCode) {
return $this->sendInvalidActionCodeResponse($translator);
}
/**
* @var User $user
*/
$user = $em->getRepository(User::class)->find($user_id);
if (!$user) {
return $this->sendInvalidActionCodeResponse($translator);
}
if ($activationKeyManager->keyIsValid($user, $activationCode)) {
$user->setActive(true);
$em->flush($user);
return new JsonResponse(['status' => 'success' , 'details' => $translator->trans('Your account has been activated.')]);
} else {
return $this->sendInvalidActionCodeResponse($translator);
}
}
/**
* @param TranslatorInterface $translator
* @return JsonResponse
*/
private function sendInvalidActionCodeResponse(TranslatorInterface $translator)
{
return new JsonResponse(['status' => 'error' , 'details' => $translator->trans('The provided activation code is not valid.')], Response::HTTP_BAD_REQUEST);
}
}
php interview-questions mvc controller symfony2
New contributor
EresDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Can you be more specific in your title and description? "Controller" is a very broad purpose for your code!
– Toby Speight
yesterday
@TobySpeight I am not sure how can I be more specific. Symfony is an MVC framework and the above code is of a controller in which each public method above handles a specific request and produces response for that request with the help of services.
– EresDev
yesterday
What distinguishes your controller from any other? I don't know the library or language, but if there was only one reasonable controller, wouldn't that just be provided?
– Toby Speight
yesterday
Here is how Symfony defines a controller: "A controller is a PHP function you create that reads information from the Request object and creates and returns a Response object. The response could be an HTML page, JSON, XML, a file download, a redirect, a 404 error or anything else you can dream up. The controller executes whatever arbitrary logic your application needs to render the content of a page." My controller can be different from other controller only by being better that is, doing minimum number of tasks by itself and assigning maximum tasks to other services (classes).
– EresDev
yesterday
There is going to be a different controller for almost every different request (user registeration, user sign in, newsletter, contact etc.) So, no there is not going to be only one controller.
– EresDev
yesterday
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've been in an interview some time ago. They objected my Symfony API code with following line:
Too much code in controller actions. Can be moved to services to keep
the business logic apart from the representation. Also violating
single responsibility.
I have been trying to improve my code since then. Trying to bring SOLID in my code design and writing services for different tasks.
Now I am working on an app where I have written a controller. It still looks bulky even though it is just using services.
There are two methods:
- Register, to register user, add user to database and send activation code to their email
- Activate, get activation code from URL and activate the user or show error.
I want to know if there is any room for improvement here.
namespace AppController;
use AppEntityUser;
use AppFormUserType;
use AppSerializerFormErrorSerializer;
use AppUtilsActivationKeyManager;
use DoctrineORMEntityManagerInterface;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationJsonResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingGeneratorUrlGenerator;
use SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface;
use SymfonyComponentTranslationTranslatorInterface;
/**
* Class AuthController
* @package AppController
*/
class AuthController extends AbstractController
{
/**
* @param Request $request
* @param TranslatorInterface $translator
* @param EntityManagerInterface $em
* @param UserPasswordEncoderInterface $encoder
* @param FormErrorSerializer $formErrorSerializer
* @param ActivationKeyManager $activationKeyManager
* @param Swift_Mailer $mailer
* @return JsonResponse
*/
public function register(
Request $request,
TranslatorInterface $translator,
EntityManagerInterface $em,
UserPasswordEncoderInterface $encoder,
FormErrorSerializer $formErrorSerializer,
ActivationKeyManager $activationKeyManager,
Swift_Mailer $mailer
) : JsonResponse {
$form = $this->createForm(UserType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/**
* @var User $user
*/
$user = $form->getData();
$encoded = $encoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($encoded);
$em->persist( $user );
$em->flush();
$activationLink = $this->generateUrl(
'activate',
[
'code' => $activationKeyManager->getKey($user),
'user' => $user->getId()
],
UrlGenerator::ABSOLUTE_URL
);
$message = (new Swift_Message($translator->trans('Activate your account')))
->setFrom($this->getParameter('admin_email'))
->setTo($user->getEmail())
->setBody(
$this->renderView(
'emails/registration.txt.twig',
['activationLink' => $activationLink]
),
'text/plain'
);
$mailer->send($message);
return new JsonResponse(['status' => 'success' , 'details' => $translator->trans('User has been created successfully.')]);
}
return new JsonResponse(['status' => 'error' , 'details' => $formErrorSerializer->convertFormToArray($form)], Response::HTTP_BAD_REQUEST);
}
/**
* @param Request $request
* @param TranslatorInterface $translator
* @param EntityManagerInterface $em
* @param ActivationKeyManager $activationKeyManager
* @return JsonResponse
*/
public function activate(
Request $request,
TranslatorInterface $translator,
EntityManagerInterface $em,
ActivationKeyManager $activationKeyManager
) {
$user_id = $request->get('user');
$activationCode = $request->get('code');
if (!$user_id || !$activationCode) {
return $this->sendInvalidActionCodeResponse($translator);
}
/**
* @var User $user
*/
$user = $em->getRepository(User::class)->find($user_id);
if (!$user) {
return $this->sendInvalidActionCodeResponse($translator);
}
if ($activationKeyManager->keyIsValid($user, $activationCode)) {
$user->setActive(true);
$em->flush($user);
return new JsonResponse(['status' => 'success' , 'details' => $translator->trans('Your account has been activated.')]);
} else {
return $this->sendInvalidActionCodeResponse($translator);
}
}
/**
* @param TranslatorInterface $translator
* @return JsonResponse
*/
private function sendInvalidActionCodeResponse(TranslatorInterface $translator)
{
return new JsonResponse(['status' => 'error' , 'details' => $translator->trans('The provided activation code is not valid.')], Response::HTTP_BAD_REQUEST);
}
}
php interview-questions mvc controller symfony2
New contributor
EresDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I've been in an interview some time ago. They objected my Symfony API code with following line:
Too much code in controller actions. Can be moved to services to keep
the business logic apart from the representation. Also violating
single responsibility.
I have been trying to improve my code since then. Trying to bring SOLID in my code design and writing services for different tasks.
Now I am working on an app where I have written a controller. It still looks bulky even though it is just using services.
There are two methods:
- Register, to register user, add user to database and send activation code to their email
- Activate, get activation code from URL and activate the user or show error.
I want to know if there is any room for improvement here.
namespace AppController;
use AppEntityUser;
use AppFormUserType;
use AppSerializerFormErrorSerializer;
use AppUtilsActivationKeyManager;
use DoctrineORMEntityManagerInterface;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationJsonResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingGeneratorUrlGenerator;
use SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface;
use SymfonyComponentTranslationTranslatorInterface;
/**
* Class AuthController
* @package AppController
*/
class AuthController extends AbstractController
{
/**
* @param Request $request
* @param TranslatorInterface $translator
* @param EntityManagerInterface $em
* @param UserPasswordEncoderInterface $encoder
* @param FormErrorSerializer $formErrorSerializer
* @param ActivationKeyManager $activationKeyManager
* @param Swift_Mailer $mailer
* @return JsonResponse
*/
public function register(
Request $request,
TranslatorInterface $translator,
EntityManagerInterface $em,
UserPasswordEncoderInterface $encoder,
FormErrorSerializer $formErrorSerializer,
ActivationKeyManager $activationKeyManager,
Swift_Mailer $mailer
) : JsonResponse {
$form = $this->createForm(UserType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/**
* @var User $user
*/
$user = $form->getData();
$encoded = $encoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($encoded);
$em->persist( $user );
$em->flush();
$activationLink = $this->generateUrl(
'activate',
[
'code' => $activationKeyManager->getKey($user),
'user' => $user->getId()
],
UrlGenerator::ABSOLUTE_URL
);
$message = (new Swift_Message($translator->trans('Activate your account')))
->setFrom($this->getParameter('admin_email'))
->setTo($user->getEmail())
->setBody(
$this->renderView(
'emails/registration.txt.twig',
['activationLink' => $activationLink]
),
'text/plain'
);
$mailer->send($message);
return new JsonResponse(['status' => 'success' , 'details' => $translator->trans('User has been created successfully.')]);
}
return new JsonResponse(['status' => 'error' , 'details' => $formErrorSerializer->convertFormToArray($form)], Response::HTTP_BAD_REQUEST);
}
/**
* @param Request $request
* @param TranslatorInterface $translator
* @param EntityManagerInterface $em
* @param ActivationKeyManager $activationKeyManager
* @return JsonResponse
*/
public function activate(
Request $request,
TranslatorInterface $translator,
EntityManagerInterface $em,
ActivationKeyManager $activationKeyManager
) {
$user_id = $request->get('user');
$activationCode = $request->get('code');
if (!$user_id || !$activationCode) {
return $this->sendInvalidActionCodeResponse($translator);
}
/**
* @var User $user
*/
$user = $em->getRepository(User::class)->find($user_id);
if (!$user) {
return $this->sendInvalidActionCodeResponse($translator);
}
if ($activationKeyManager->keyIsValid($user, $activationCode)) {
$user->setActive(true);
$em->flush($user);
return new JsonResponse(['status' => 'success' , 'details' => $translator->trans('Your account has been activated.')]);
} else {
return $this->sendInvalidActionCodeResponse($translator);
}
}
/**
* @param TranslatorInterface $translator
* @return JsonResponse
*/
private function sendInvalidActionCodeResponse(TranslatorInterface $translator)
{
return new JsonResponse(['status' => 'error' , 'details' => $translator->trans('The provided activation code is not valid.')], Response::HTTP_BAD_REQUEST);
}
}
php interview-questions mvc controller symfony2
php interview-questions mvc controller symfony2
New contributor
EresDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
EresDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited yesterday
200_success
127k15149412
127k15149412
New contributor
EresDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked yesterday
EresDev
1012
1012
New contributor
EresDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
EresDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
EresDev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Can you be more specific in your title and description? "Controller" is a very broad purpose for your code!
– Toby Speight
yesterday
@TobySpeight I am not sure how can I be more specific. Symfony is an MVC framework and the above code is of a controller in which each public method above handles a specific request and produces response for that request with the help of services.
– EresDev
yesterday
What distinguishes your controller from any other? I don't know the library or language, but if there was only one reasonable controller, wouldn't that just be provided?
– Toby Speight
yesterday
Here is how Symfony defines a controller: "A controller is a PHP function you create that reads information from the Request object and creates and returns a Response object. The response could be an HTML page, JSON, XML, a file download, a redirect, a 404 error or anything else you can dream up. The controller executes whatever arbitrary logic your application needs to render the content of a page." My controller can be different from other controller only by being better that is, doing minimum number of tasks by itself and assigning maximum tasks to other services (classes).
– EresDev
yesterday
There is going to be a different controller for almost every different request (user registeration, user sign in, newsletter, contact etc.) So, no there is not going to be only one controller.
– EresDev
yesterday
|
show 1 more comment
Can you be more specific in your title and description? "Controller" is a very broad purpose for your code!
– Toby Speight
yesterday
@TobySpeight I am not sure how can I be more specific. Symfony is an MVC framework and the above code is of a controller in which each public method above handles a specific request and produces response for that request with the help of services.
– EresDev
yesterday
What distinguishes your controller from any other? I don't know the library or language, but if there was only one reasonable controller, wouldn't that just be provided?
– Toby Speight
yesterday
Here is how Symfony defines a controller: "A controller is a PHP function you create that reads information from the Request object and creates and returns a Response object. The response could be an HTML page, JSON, XML, a file download, a redirect, a 404 error or anything else you can dream up. The controller executes whatever arbitrary logic your application needs to render the content of a page." My controller can be different from other controller only by being better that is, doing minimum number of tasks by itself and assigning maximum tasks to other services (classes).
– EresDev
yesterday
There is going to be a different controller for almost every different request (user registeration, user sign in, newsletter, contact etc.) So, no there is not going to be only one controller.
– EresDev
yesterday
Can you be more specific in your title and description? "Controller" is a very broad purpose for your code!
– Toby Speight
yesterday
Can you be more specific in your title and description? "Controller" is a very broad purpose for your code!
– Toby Speight
yesterday
@TobySpeight I am not sure how can I be more specific. Symfony is an MVC framework and the above code is of a controller in which each public method above handles a specific request and produces response for that request with the help of services.
– EresDev
yesterday
@TobySpeight I am not sure how can I be more specific. Symfony is an MVC framework and the above code is of a controller in which each public method above handles a specific request and produces response for that request with the help of services.
– EresDev
yesterday
What distinguishes your controller from any other? I don't know the library or language, but if there was only one reasonable controller, wouldn't that just be provided?
– Toby Speight
yesterday
What distinguishes your controller from any other? I don't know the library or language, but if there was only one reasonable controller, wouldn't that just be provided?
– Toby Speight
yesterday
Here is how Symfony defines a controller: "A controller is a PHP function you create that reads information from the Request object and creates and returns a Response object. The response could be an HTML page, JSON, XML, a file download, a redirect, a 404 error or anything else you can dream up. The controller executes whatever arbitrary logic your application needs to render the content of a page." My controller can be different from other controller only by being better that is, doing minimum number of tasks by itself and assigning maximum tasks to other services (classes).
– EresDev
yesterday
Here is how Symfony defines a controller: "A controller is a PHP function you create that reads information from the Request object and creates and returns a Response object. The response could be an HTML page, JSON, XML, a file download, a redirect, a 404 error or anything else you can dream up. The controller executes whatever arbitrary logic your application needs to render the content of a page." My controller can be different from other controller only by being better that is, doing minimum number of tasks by itself and assigning maximum tasks to other services (classes).
– EresDev
yesterday
There is going to be a different controller for almost every different request (user registeration, user sign in, newsletter, contact etc.) So, no there is not going to be only one controller.
– EresDev
yesterday
There is going to be a different controller for almost every different request (user registeration, user sign in, newsletter, contact etc.) So, no there is not going to be only one controller.
– EresDev
yesterday
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
EresDev is a new contributor. Be nice, and check out our Code of Conduct.
EresDev is a new contributor. Be nice, and check out our Code of Conduct.
EresDev is a new contributor. Be nice, and check out our Code of Conduct.
EresDev is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208927%2fsymfony-controller-to-register-and-activate-users%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you be more specific in your title and description? "Controller" is a very broad purpose for your code!
– Toby Speight
yesterday
@TobySpeight I am not sure how can I be more specific. Symfony is an MVC framework and the above code is of a controller in which each public method above handles a specific request and produces response for that request with the help of services.
– EresDev
yesterday
What distinguishes your controller from any other? I don't know the library or language, but if there was only one reasonable controller, wouldn't that just be provided?
– Toby Speight
yesterday
Here is how Symfony defines a controller: "A controller is a PHP function you create that reads information from the Request object and creates and returns a Response object. The response could be an HTML page, JSON, XML, a file download, a redirect, a 404 error or anything else you can dream up. The controller executes whatever arbitrary logic your application needs to render the content of a page." My controller can be different from other controller only by being better that is, doing minimum number of tasks by itself and assigning maximum tasks to other services (classes).
– EresDev
yesterday
There is going to be a different controller for almost every different request (user registeration, user sign in, newsletter, contact etc.) So, no there is not going to be only one controller.
– EresDev
yesterday