Rovak / KJSencha

Ext-JS / Sencha Touch Integration Module for Zend Framework 2
Other
24 stars 15 forks source link

Uploading file form #18

Closed catalinux closed 11 years ago

catalinux commented 11 years ago

Do you have any example for uploading a file. I have some problems.

My javascript looks likee

    var fileInfo = Ext.create('Ext.form.Panel', {
        title:'Upload a Photo',
        width:400,
        bodyPadding:10,
        frame:true,
        fileUpload:true,
        items:[
            {
                xtype:'filefield',
                name:'photo',
                fieldLabel:'Photo',
                labelWidth:50,
                msgTarget:'side',
                allowBlank:false,
                anchor:'100%',
                buttonText:'Select Photo...'
            }
        ],
        success:function () {
            console.log(arguments);
        },
        failure:function () {
            console.log(arguments);
        },
        api:{

            // The server-side must mark the submit handler as a 'formHandler'
            submit:Application.Direct.form.Profile.updateBasicInfo2
        },

THe problem seems to be here:

$result = new JsonModel($result);

    // Wrap the result when its a form request
    if ($this->isForm() && $this->isUpload()) {
        $result = '<html><body><textarea>' . JsonFormatter::encode($result) . '</textarea></body></html>';
    }

    $e->setResult($result);

Unfortunately the response is not as I would expect:

When $result is string, the html reandered is smth similar to:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>KJSencha Example Application</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- Le styles -->
        <link href="http://cdn.sencha.io/ext-4.1.1-gpl/resources/css/ext-all.css" media="screen" rel="stylesheet" type="text/css">
<link href="http://cdn.sencha.io/ext-4.1.1-gpl/examples/shared/example.css" media="screen" rel="stylesheet" type="text/css">
<link href="/zend/kj-sencha-example/public/css/style.css" media="screen" rel="stylesheet" type="text/css">
        <!-- Scripts -->
            </head>
    <body>
                <script type="text/javascript" src="/zend/kj-sencha-example/public/js/app/app.js"></script>    </body>
</html>
Rovak commented 11 years ago

I'm looking into it, the problem is indeed a wrong return value and should be replaced by a return Response->setContent call. I will fix the problem and add an example in the KJSenchaExample application and update this issue when its available.

Rovak commented 11 years ago

@catalinux The fix has been merged, please let me know if this fixes your problem.

An example can be found in the KJSenchaExample application right here. The documentation can be found here

catalinux commented 11 years ago

It works like magic! Thanx