Answer the question
In order to leave comments, you need to log in
How to push JSON into Response?
The root of the question lies here stackoverflow.com/questions/28683727/submit-form-w... .
The bottom line is that you can't use $form->handleRequest($request), because The JSON is not in the $request object, but is available via $request->getContent() .
Actually the question is: how to competently shove JSON into $request without using crutches?
Answer the question
In order to leave comments, you need to log in
$request = $request->duplicate(null, json_decode($request->getContent()));
Today I helped a friend with Silex "ohm and there is such a thing
$app->before(function (Request $request) {
if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
$data = json_decode($request->getContent(), true);
$request->request->replace(is_array($data) ? $data : array());
}
});
in theory, this can be entered directly into the Request class, here in this function
public static function createFromGlobals()
{
// With the php's bug #66606, the php's built-in web server
// stores the Content-Type and Content-Length header values in
// HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH fields.
$server = $_SERVER;
if ('cli-server' === php_sapi_name()) {
if (array_key_exists('HTTP_CONTENT_LENGTH', $_SERVER)) {
$server['CONTENT_LENGTH'] = $_SERVER['HTTP_CONTENT_LENGTH'];
}
if (array_key_exists('HTTP_CONTENT_TYPE', $_SERVER)) {
$server['CONTENT_TYPE'] = $_SERVER['HTTP_CONTENT_TYPE'];
}
}
$request = self::createRequestFromFactory($_GET, $_POST, array(), $_COOKIE, $_FILES, $server);
if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded')
&& in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH'))
) {
parse_str($request->getContent(), $data);
$request->request = new ParameterBag($data);
}
return $request;
}
How about this option:
$content = $this->get("request")->getContent();
$params = json_decode($content, true);
$request->request->add($params);
For a start - to write down request more clearly. In ON conditions, write the fields of the attached table in the left parts of the comparisons:
SELECT *
FROM `tbl_1`
LEFT JOIN `tbl_2` ON `tbl_2`.`id_fp` = `tbl_1`.`foto_id` AND `tbl_2`.`sklad` = 'Склад'
WHERE (deleted="no" AND `where`="arh") AND (`type`="Cloth" )
ORDER BY `foto_id` ASC
LIMIT 9447,20;
SELECT *
FROM (
SELECT *
FROM `tbl_1`
WHERE (deleted="no" AND `where`="arh") AND (`type`="Cloth" )
ORDER BY `foto_id` ASC
LIMIT 9447,20
) AS `t1`
LEFT JOIN `tbl_2` ON `tbl_2`.`id_fp` = `t1`.`foto_id` AND `tbl_2`.`sklad` = 'Склад'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question