【发布时间】: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