Closed cbourgois closed 10 years ago
If you put a breakpoint on the line bellow, what is the value of data ?
if (typeof data != 'string' && data.result == 'ok') {
I've added a debugger;
before if
test.
The Local Scope contains:
data : "{"result":"ok","objectId":"240"}"
this: Object
So data
contains:
{"result":"ok","objectId":"240"}
The response Header of /sonata/media/media/create?provider=sonata.media.provider.file&context=documentations&uniqid=s52947db431bf7
is
Cache-Control:private
Connection:close
Content-Type:text/plain; charset=UTF-8
Date:Tue, 26 Nov 2013 10:53:59 GMT
Host:localhost:8000
X-Debug-Token:539be8
X-Powered-By:PHP/5.4.4
Is it normal that response is in text/plain
?
No it is not normal ...
Thomas Rabaix http://rabaix.net - http://sonata-project.org On Nov 26, 2013 11:59 AM, "Cyrille Bourgois" notifications@github.com wrote:
I've added a debugger; before if test.
The Local Scope contains:
data : "{"result":"ok","objectId":"240"}" this: Object
So data contains:
{"result":"ok","objectId":"240"}
The response Header of /sonata/media/media/create?provider=sonata.media.provider.file&context=documentations&uniqid=s52947db431bf7is
Cache-Control:private Connection:close Content-Type:text/plain; charset=UTF-8 Date:Tue, 26 Nov 2013 10:53:59 GMT Host:localhost:8000 X-Debug-Token:539be8 X-Powered-By:PHP/5.4.4
Is it normal that response is in text/plain ?
— Reply to this email directly or view it on GitHubhttps://github.com/sonata-project/SonataAdminBundle/issues/1815#issuecomment-29283428 .
Ok, I found that if I change code below in /vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Controller/CRUDController.php
it works.
Original :
public function renderJson($data, $status = 200, $headers = array())
{
// fake content-type so browser does not show the download popup when this
// response is rendered through an iframe (used by the jquery.form.js plugin)
// => don't know yet if it is the best solution
if ($this->get('request')->get('_xml_http_request')
&& strpos($this->get('request')->headers->get('Content-Type'), 'multipart/form-data') === 0) {
$headers['Content-Type'] = 'text/plain';
} else {
$headers['Content-Type'] = 'application/json';
}
return new Response(json_encode($data), $status, $headers);
}
Modified version (force Response Content-Type to application/json
):
public function renderJson($data, $status = 200, $headers = array())
{
// fake content-type so browser does not show the download popup when this
// response is rendered through an iframe (used by the jquery.form.js plugin)
// => don't know yet if it is the best solution
if ($this->get('request')->get('_xml_http_request')
&& strpos($this->get('request')->headers->get('Content-Type'), 'multipart/form-data') === 0) {
$headers['Content-Type'] = 'application/json';
} else {
$headers['Content-Type'] = 'application/json';
}
return new Response(json_encode($data), $status, $headers);
}
Any Idea ?
Which version (the commit SHA is the best) of SonataAdminBundle are you using ?
I have defined in my composer.json
:
"sonata-project/admin-bundle": "dev-master"
In my composer.lock
I read :
{
"name": "sonata-project/admin-bundle",
"version": "dev-master",
"target-dir": "Sonata/AdminBundle",
"source": {
"type": "git",
"url": "https://github.com/sonata-project/SonataAdminBundle.git",
"reference": "d02b7e0b5246556c338ba004050db4f456f06690"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sonata-project/SonataAdminBundle/zipball/d02b7e0b5246556c338ba004050db4f456f06690",
"reference": "d02b7e0b5246556c338ba004050db4f456f06690",
"shasum": ""
},
"require": {
"doctrine/common": "~2.2",
"knplabs/knp-menu-bundle": "~1.1",
"sensio/generator-bundle": "~2.2",
"sonata-project/block-bundle": "~2.2,>=2.2.7",
"sonata-project/exporter": "1.*",
"sonata-project/jquery-bundle": "1.8.*",
"symfony/class-loader": "~2.2",
"symfony/config": "~2.2",
"symfony/console": "~2.2",
"symfony/form": "~2.2",
"symfony/http-foundation": "~2.2",
"symfony/routing": "~2.2",
"symfony/security-bundle": "~2.2",
"symfony/twig-bridge": "~2.2",
"symfony/validator": "~2.2",
"twig/extensions": "~1.0",
"twig/twig": "~1.12"
},
"require-dev": {
"jms/translation-bundle": "*@dev",
"sonata-project/intl-bundle": "~2.1",
"symfony/yaml": "~2.2"
},
"suggest": {
"sonata-project/doctrine-orm-admin-bundle": "2.2.*@dev",
"sonata-project/intl-bundle": "2.1.*"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.2.x-dev"
}
},
"autoload": {
"psr-0": {
"Sonata\\AdminBundle": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Thomas Rabaix",
"email": "thomas.rabaix@sonata-project.org",
"homepage": "http://sonata-project.org"
},
{
"name": "Sonata Community",
"homepage": "https://github.com/sonata-project/SonataAdminBundle/contributors"
}
],
"description": "Symfony SonataAdminBundle",
"homepage": "http://sonata-project.org/bundles/admin",
"keywords": [
"Admin Generator",
"admin",
"bootstrap",
"sonata"
],
"time": "2013-11-25 11:47:35"
},
Where I can find the sha1 ?
It's the in source.reference
, the SHA1 is d02b7e0b5246556c338ba004050db4f456f06690, it's the current master of SonataAdminBundle. I'll have a look, it was working on previous releases...
Hi,
any update? Will it be available again in HEAD?
I have reverted the code, so this should work fine now.
ping me if not
I have an admin with a field defined like this:
When I click to add file, a model opens, I add a file and send the form, it displays a JSON response in the dialog:
The console output is :
It seems that response is considered as string (this part of auto generated code is not executed) :
This bug is similar to sonata-project/SonataAdminBundle#247, but solution isn't appropriate (my entity has a
setFile
function)Any Idea ?