symfony - How to refer to route name with FOSRestBundle -
candidate controller
class defaultcontroller extends previewmecontroller { /** * complete registration process candidate * * @apidoc( * section="candidate", * tags={"common"}, * ) * * @rest\view() * @post("/ua/register/candidate/{token}") * * @param request $request * @return \fos\restbundle\view\view */ public function registercandidateaction($token) { } }
candidate routing.yml
candidate_api_routes: type: rest prefix: /v1 resource: "candidatebundle\controller\defaultcontroller" name_prefix: "api_1_c_"
appbundle controller
/** * register new user on website * * @apidoc( * section="common functionalities", * tags={"common"}, * requirements={ * {"name"="email", "datatype"="string", "description"="email of user"}, * {"name"="username", "datatype"="string", "description"="username. keep same email address"}, * {"name"="first_name", "datatype"="string", "description"="first name of user"}, * {"name"="last_name", "datatype"="string", "description"="last name of user"}, * {"name"="plainpassword", "datatype"="array", "requirement"="['first':'password','second':'password']", "description"="plain password. send array 'first' , 'second' array keys"}, * {"name"="user_type","datatype"="string","requirement"="employer|candidate","description"="employer or candidate user type"} * }, * statuscodes={ * 200 = "when user registered", * 400="when there validation error in registration process" * } * ) * @post("/ua/register") * @rest\view() * * @param request $request * @return array|\fos\restbundle\view\view */ public function registeraction(request $request) { /** @var $formfactory \fos\userbundle\form\factory\factoryinterface */ $formfactory = $this->get('fos_user.registration.form.factory'); /** @var usermanager $fos_usermanager */ $fos_usermanager = $this->get('fos_user.user_manager'); /** @var user $user */ $user = $fos_usermanager->createuser(); $user->setenabled(true); $user->setusertype($request->request->get('user_type')); //remove user_type request it's not forwarded form $request->request->remove('user_type'); $form = $formfactory->createform(); $form->setdata($user); $form->submit($request->request->all()); if( $form->isvalid() ){ $event = new userevent($user); $dispatcher = $this->get('event_dispatcher'); $dispatcher->dispatch(pmevents::registration_success, $event); $fos_usermanager->updateuser($user); $wrapper = new pmresponsewrapper(); $wrapper->setdata(array( 'ob_key' => $user->getobkey() )); /** @var view $response */ $response = view::create($wrapper->getformatteddata()); $response->setlocation( $this->generateurl('register_candidate') ); return $response; } return $this->view($form); }
app/console debug:router dump
api_1_register post /api/v1/ua/register api_1_register_confirm_token post /api/v1/ua/register/confirm_token/{token} api_1_c_index /api/v1/index api_1_c_register_candidate post /api/v1/ua/register/candidate/{token}
problem though registercandidateaction
shows in debug:router
, not able call $this->generateurl()
in registeraction
.
when call line $response->setnexturl($this->generateurl('register_candidate'));
error unable generate url named route \"register_candidate\" such route not exist.
please in finding what's wrong here.
Comments
Post a Comment