I am new in Symfony, and trying to fix a bug. I am getting Access-Control-Allow-Origin header is present on the requested resource error while inserting data via restApi.
This is a restful api that is sending data in the given format:
{"default_runs":["24"],"date":1451932200,"driver":107}
Controller
public function postScheduleAction(Request $request)
{   
    $user = $this->getUser();
    $user_id = $user->getId();
    $entity = new Schedule();
    $form = $this->createForm(new ScheduleType(), $entity);
    $now = time();
    $data = json_decode($request->getContent(), true);
    $data["is_default"] = true;
    $data["status"] = 0;            
    $finalData = array_merge($data,array("created_time"=>$now,"created_by"=>$user_id));
    $request->request->replace(is_array($finalData) ? $finalData : array());
    //I have checked, code is working fine till this line,
    //but after bind the form it gives me error
    $form->bind($request);
    if ($form->isValid()) {
        $em = $this->getDoctrine()->getManager();
        $em->persist($entity);
        $em->flush();
        return array(
            'id' => $entity->getId(),
        );
    }
    return array(
        'form' => $form,
    );
}
Conclusion after debugging
I have searched a lot, dump on every line, at the last I have change the insert function of symfony with custom php-msql insert query then it works fine.
So now I know that there is any error with the $form->bind($request); line, it through any fetal error that missed the Access-Control-Allow-Origin header and I get that error.
Can some one please help me to catch the error in $form->bind($request);, so that I can fix that error.
Thanks
 
     
     
    