You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ExtJS PHP/MySQL后端连接器报错,按官方文档配置仍未解决

ExtJS 6.5.3 Ext Direct PHP/MySQL Connector Error (Matches Stack Overflow Post)

我在按照ExtJS 6.5.3官方文档配置PHP/MySQL后端连接器时,遇到了和某篇Stack Overflow帖子完全一致的错误。我已经参照SDK示例编写了api.php、router.php等代码,完成了app.json和application.js的相关配置,但问题仍未解决。以下是Firefox控制台截图(截图说明:控制台显示Ext Direct远程调用相关错误)以及所有相关代码片段:

相关代码片段

api.php

<?php require('config.php'); header('Content-Type: text/javascript'); $API = get_extdirect_api('api'); # convert API config to Ext Direct spec $actions = array(); foreach($API as $aname=>&$a){ $methods = array(); foreach($a['methods'] as $mname=>&$m){ if (isset($m['len'])) { $md = array( 'name'=>$mname, 'len'=>$m['len'] ); } else { $md = array( 'name'=>$mname, 'params'=>$m['params'] ); } if(isset($m['formHandler']) && $m['formHandler']){ $md['formHandler'] = true; } if (isset($m['metadata'])) { $md['metadata'] = $m['metadata']; } $methods[] = $md; } $actions[$aname] = $methods; } $cfg = array( 'url'=>'data/direct/router.php', 'type'=>'remoting', 'actions'=>$actions ); echo 'var Ext = Ext || {}; Ext.REMOTING_API = '; echo json_encode($cfg); echo ';'; ?>

app.json 相关配置

"js": [ { "path": "${framework.dir}/build/ext-all-rtl-debug.js" }, { "path": "php/api.php", "remote": true }, { "path": "app.js", "bundle": true } ],

application.js

/** * The main application class. An instance of this class is created by app.js when it * calls Ext.application(). This is the ideal place to handle application launch and * initialization details. */ Ext.define('DirectApp.Application', { extend: 'Ext.app.Application', name: 'DirectApp', quickTips: false, platformConfig: { desktop: { quickTips: true } }, launch: function () { Ext.direct.Manager.addProvider(Ext.REMOTING_API); }, onAppUpdate: function () { Ext.Msg.confirm('Application Update', 'This application has an update, reload?', function (choice) { if (choice === 'yes') { window.location.reload(); } } ); } });

index.html

<!DOCTYPE HTML> <html manifest=""> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=10, user-scalable=yes"> <title>DirectApp</title> <!-- The line below must be kept intact for Sencha Cmd to build your application --> <script id="microloader" data-app="70f32dd6-f700-4939-bc96-3af4f1c9798b" type="text/javascript" src="bootstrap.js"></script> </head> <body></body> </html>

router.php

<?php require('config.php'); class BogusAction { public $action; public $method; public $data; public $tid; } $isForm = false; $isUpload = false; if(isset($HTTP_RAW_POST_DATA)){ header('Content-Type: text/javascript'); $data = json_decode($HTTP_RAW_POST_DATA); }else if(isset($_POST['extAction'])) { // form post $isForm = true; $isUpload = $_POST['extUpload'] == 'true'; $data = new BogusAction(); $data->action = $_POST['extAction']; $data->method = $_POST['extMethod']; $data->tid = isset($_POST['extTID']) ? $_POST['extTID'] : null; // not set for upload $data->data = array($_POST, $_FILES); }else if (($data = file_get_contents('php://input')) !== '') { $data = json_decode($data); }else{ die('Invalid request.'); } function doRpc($cdata){ $API = get_extdirect_api('router'); try { if(!isset($API[$cdata->action])){ throw new Exception('Call to undefined action: ' . $cdata->action); } $action = $cdata->action; $a = $API[$action]; doAroundCalls($a['before'], $cdata); $method = $cdata->method; $mdef = $a['methods'][$method]; if(!$mdef){ throw new Exception("Call to undefined method: $method on action $action"); } doAroundCalls($mdef['before'], $cdata); $r = array( 'type'=>'rpc', 'tid'=>$cdata->tid, 'action'=>$action, 'method'=>$method ); require_once("classes/$action.php"); $o = new $action(); if (isset($mdef['len'])) { $params = isset($cdata->data) && is_array($cdata->data) ? $cdata->data : array(); } else { $params = array($cdata->data); } array_push($params, $cdata->metadata); $r['result'] = call_user_func_array(array($o, $method), $params); doAroundCalls($mdef['after'], $cdata, $r); doAroundCalls($a['after'], $cdata, $r); } catch(Exception $e){ $r['type'] = 'exception'; $r['message'] = $e->getMessage(); $r['wh

内容的提问来源于stack exchange,提问作者RomAZE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:08:51