【问题标题】:sencha Architect (Touch) - the Store don't read my php filesencha Architect (Touch) - 商店不读取我的 php 文件
【发布时间】:2014-07-02 13:33:29
【问题描述】:

我在使用 Store 读取我的 php 文件时遇到问题。我认为问题在于 php 文件中的 base64_encode 命令。 我解释一下。在我的 php 中,我采用 sql 代码的路径,之后,通过这条路径,我得到了真实的图像。在我需要将结果保存在一个数组中之后,给 sencha 架构师。 这是php代码:

require("db.php");
    session_start();
    $filepath='';
    $sql = "SELECT concat('C:/wamp/www/Tecnitalia_Optic/app/webroot/img/',folder) as Path, thumb as FileName FROM frames ";
    $result = array();
    if ($resultdb = $mysqli->query($sql)) {
    while($record = $resultdb->fetch_array()) {
        $filepath = $record['Path'];
        $nomeFile = $record['FileName'];
        $mimetype = pathinfo($nomeFile, PATHINFO_EXTENSION);
        $filedata=filesize($filepath."/".$nomeFile);
        header('Content-Type: '.$mimetype);
        header('Content-Disposition: attachment; filename="'.$nomeFile.'"');
        header('Content-Transfer-Encoding: binary');
        header('Content-Length: '.sprintf('%d', $filedata));
        header('Expires: 0');
        //readfile($filepath."/".$nomeFile);
        $recordnew = readfile($filepath."/".$nomeFile);
        $result[] = $recordnew;
    }
    $resultdb->close();
    }
    //count total records from table for paging
    $sql = "SELECT count(*) as num FROM frames ";
    $total = 0;
    if ($resultdb = $mysqli->query($sql)) {
    $record = $resultdb->fetch_assoc();
    $total = $record['num'];
    $resultdb->close();
    }
    //send back information to sencha architect touch
    echo json_encode(array(
    "success" => $mysqli->connect_errno == 0,
    "total" => $total,
    "data" => base64_encode($result)
    )); 
    /* close connection */
    $mysqli->close();

之后,在 SA 中,我创建了一个模型,其中包含一个类型为 auto 的字段。在我创建了一个带有模型的 Json Store 链接后,商店告诉我:MyJsonReader 无法读取数据。在浏览器中打开:api/frames.php

这是我的煎茶架构师代码:

模型和商店

Ext.define('ciaopoint2.model.frames', {
    extend: 'Ext.data.Model',
     requires: [
        'Ext.data.Field'
    ],
    config: {
        fields: [
            {
                name: 'mini',
                type: 'auto'
            }
        ]
    }
    });
Ext.define('ciaopoint2.store.Frames', {
extend: 'Ext.data.Store',
alias: 'store.frames',
requires: [
    'ciaopoint2.model.frames',
    'Ext.data.proxy.Ajax',
    'Ext.data.reader.Json'
],
config: {
    autoLoad: true,
    model: 'ciaopoint2.model.frames',
    storeId: 'Frames',
    proxy: {
        type: 'ajax',
        url: 'api/frames.php',
        reader: {
            type: 'json',
            rootProperty: 'data'
        }
    }
}
});

您好 Zoltan 感谢您的回复。你能用一个例子解释你说什么吗?我取消了 base64_encode 命令,但之后我能做什么?在 Architect Touch 内部还是在 php 文件中?

【问题讨论】:

    标签: sencha-touch-2 sencha-architect


    【解决方案1】:

    我认为您不需要对结果进行 base64 编码,但您需要 JSON 编码来递归编码您的返回值(即数据 par 也应该是 json 编码值)。

    【讨论】:

    • HI Zoltan 谢谢您的回复。你能用一个例子解释你说什么吗?我取消了 base64_encode 命令,但之后我能做什么?在 Architect Touch 内部还是在 php 文件中?
    • 现在我只有这个代码: echo json_encode(array( "success" => $mysqli->connect_errno == 0, "total" => $total, "data" => $result ) );我采用 base64_encode 但 Sencha 不阅读我的 php
    • 你现在得到了什么?只是没有看到商店加载?你有没有在某个地方公开你的服务器代码以便我看一下?
    • 嗨,佐尔坦。我已经解决了。问题是 php.ini 中的 readfile 命令。正确的命令是 file_get_command。谢谢
    猜你喜欢
    • 2012-05-29
    • 2014-01-25
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 2012-01-14
    • 2013-07-14
    • 2011-09-01
    • 2014-03-03
    相关资源
    最近更新 更多