Background:
I am writing a RESTful API in symfony. I want the client to be able to publish the URL using an application like content / json and publish the json object of the form that is looking for the controller action.
I am using a fairly basic controller setup for this. Let's assume for demonstration purposes that they are trying to authenticate a simple combination of username passwords.
public function loginAction( Request $request ) { $user = new ApiUser(); $form = $this->createForm(new ApiUserType(), $user); if ( "POST" == $request->getMethod() ) { $form->bindRequest($request); if ( $form->isValid() ) { $em = $this->getDoctrine()->getEntityManager(); $repo = $this->getDoctrine()->getRepository('ApiBundle:ApiUser'); $userData = $repo->findOneByUsername($user->getUsername()); if ( is_object($userData) ) { } else{ return new Response(json_encode(array('error'=>'no user by that username found'))); } else{ return new Response(json_encode(array('error'=>'invalid form'))); } } }
Now the problem that I have, and I tried var_dumping this until the cow gets home, is that there is ever a reason why Symfony does not want to use the application / json content body and use this data to populate data forms.
Form Name: api_apiuser
Fields: username, password
What would be the best way to handle this type of task. I am open to suggestions as long as I can get this to work. Thanks for your time with this question.
php symfony
chasen
source share