src/Graviton/RestBundle/Controller/RestController.php
public function postAction(Request $request)
    {
        // Get the response object from container
        $response = $this->getResponse();
        $model = $this->getModel();

        $this->restUtils->checkJsonRequest($request, $response, $this->getModel());

        $record = $this->restUtils->validateRequest($request->getContent(), $model);

        // Insert the new record
        $record = $model->insertRecord($record);

        // store id of new record so we dont need to reparse body later when needed
        $request->attributes->set('id', $record->getId());

        // Set status code
        $response->setStatusCode(Response::HTTP_CREATED);

        $response->headers->set(
            'Location',
            $this->getRouter()->generate($this->restUtils->getRouteName($request), array('id' => $record->getId()))
        );

        return $response;
    }
public function postAction(Request $request)
    {
        // Get the response object from container
        $response = $this->getResponse();
        $model = $this->getModel();

        $this->restUtils->checkJsonRequest($request, $response, $this->getModel());

        $record = $this->restUtils->validateRequest($request->getContent(), $model);

        // Insert the new record
        $record = $model->insertRecord($record);

        // store id of new record so we dont need to reparse body later when needed
        $request->attributes->set('id', $record->getId());

        // Set status code
        $response->setStatusCode(Response::HTTP_CREATED);

        $response->headers->set(
            'Location',
            $this->getRouter()->generate($this->restUtils->getRouteName($request), array('id' => $record->getId()))
        );

        return $response;
    }
public function postAction ( Request $ request ) { // Get the response object from container $ response = $ this -> getResponse ( ) ; $ model = $ this -> getModel ( ) ; $ this -> restUtils -> checkJsonRequest ( $ request , $ response , $ this -> getModel ( ) ) ; $ record = $ this -> restUtils -> validateRequest ( $ request -> getContent ( ) , $ model ) ; // Insert the new record $ record = $ model -> insertRecord ( $ record ) ; // store id of new record so we dont need to reparse body later when needed $ request -> attributes -> set ( 'id' , $ record -> getId ( ) ) ; // Set status code $ response -> setStatusCode ( Response :: HTTP_CREATED ) ; $ response -> headers -> set ( 'Location' , $ this -> getRouter ( ) -> generate ( $ this -> restUtils -> getRouteName ( $ request ) , array ( 'id' => $ record -> getId ( ) ) ) ) ; return $ response ; }
Writes a new Entry to the database

@param Request $request Current http request

@return \Symfony\Component\HttpFoundation\Response $response Result of action with data (if successful)
Writes a new Entry to the database