ExtJS PHP/MySQL后端连接器错误 [英] ExtJS PHP/MySQL backend connector error

查看:59
本文介绍了ExtJS PHP/MySQL后端连接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仔细阅读文档(官方) https://docs.sencha.com/extjs/6.5.3/guides/backend_connectors/direct/mysql_php.html

follow carefully the documentation (official) https://docs.sencha.com/extjs/6.5.3/guides/backend_connectors/direct/mysql_php.html

不明白如何解决

编辑 这是firefox控制台的屏幕截图

api.php(错误所在的文件) (摘自ext js文档和sdk示例)

api.php (the file where the error is) (took from ext js documentation and sdk examples)

<?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按我链接的教程中的要求编辑的部分

app.json edited part as asked in the tutorial i linked

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

application.js

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

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>

这是从sdk示例中获取的路由器,因为我说您可以在本教程中做到

here is the router took from sdk examples as i say you can do it in the tutorial

<?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['where'] = $e->getTraceAsString();
    }
    return $r;
}


function doAroundCalls(&$fns, &$cdata, &$returnData=null){
    if(!$fns){
        return;
    }
    if(is_array($fns)){
        foreach($fns as $f){
            $f($cdata, $returnData);
        }
    }else{
        $fns($cdata, $returnData);
    }
}

$response = null;
if(is_array($data)){
    $response = array();
    foreach($data as $d){
        $response[] = doRpc($d);
    }
}else{
    $response = doRpc($data);
}
if($isForm && $isUpload){
    echo '<html><body><textarea>';
    echo json_encode($response);
    echo '</textarea></body></html>';
}else{
    echo json_encode($response);
}

?>

QueryDatabase.php(sql请求php文件)

QueryDatabase.php (sql request php file)

<?php

 class QueryDatabase {

    private $_db;
    protected $_result;
    public $results;

    public function __construct() {
        $this->_db = new mysqli(MY CREDENTIALS);

        $_db = $this->_db;

        if ($_db->connect_error) {
            die('Connection Error: ' . $_db->connect_error);
        }

        return $_db;
    }

    public function getResults($params) {
        $_db = $this->_db;

        $_result = $_db->query("SELECT name,email,phone FROM heroes") or
                   die('Connection Error: ' . $_db->connect_error);

        $results = array();

        while ($row = $_result->fetch_assoc()) {
            array_push($results, $row);
        }

        $this->_db->close();

        return $results;
    }
 }

最后是config.php文件

and finally config.php file

<?php

function get_extdirect_api() {
    $API = array(
        'QueryDatabase' => array(
            'methods' => array(
                'getResults' => array(
                    'len' => 1
                )
            )
        )
    );

    return $API;
}

edit2

这是Firefox屏幕截图中的完整网络"标签

here is full network tab from firefox screenshots

编辑3 这是网络"标签中的api.php详细信息

edit 3 here is api.php details from network tab

answer

标题

堆栈跟踪

这是配置文件sencha.cfg,它是提供我的sencha CMD的最小Web服务器的配置

here is the configuration file sencha.cfg which is configuration of the minimal web server provided my sencha CMD

# sencha.cfg
#
# This is the main configuration file for Sencha Cmd. The properties defined in
# this file are used to initialize Sencha Cmd and should be edited with some
# caution.
#
# On previous versions, this file provided a way to specify the cmd.jvm.* properties
# to control the execution of the JVM. To accommodate all possible execution scenarios
# support for these properties has been removed in favor of using the _JAVA_OPTIONS
# environment variable.
#

#------------------------------------------------------------------------------
# This indicates the platform that Cmd is installed on.  This is used for
# platform specific package management.
#
# Possible values: windows, osx, linux, linux-x64
#
# cmd.platform=

#------------------------------------------------------------------------------
# This is the Sencha Cmd version.
#
# THIS PROPERTY SHOULD NOT BE MODIFIED.

cmd.version=6.5.3.6

#------------------------------------------------------------------------------
# This indicates the level of backwards compatibility provided. That is to say,
# apps requiring versions between cmd.minver and cmd.version (inclusive) should
# be able to use this version.
#
# THIS PROPERTY SHOULD NOT BE MODIFIED.

cmd.minver=3.0.0.0

#------------------------------------------------------------------------------
# The folder for the local package repository. By default, this folder is shared
# by all versions of Sencha Cmd. In other words, upgrading Sencha Cmd does not
# affect the local repository.

repo.local.dir=${cmd.dir}/../repo

#------------------------------------------------------------------------------
# This is the default port to use for the Sencha Cmd Web Server.

cmd.web.port=1841

#------------------------------------------------------------------------------
# Java System Properties
#
# By setting any "system.*" properties you can set Java System Properties. For
# general information on these, see:
#
# http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
#

#------------------------------------------------------------------------------
# Proxy Settings
#
# The primary reason to set Java System Properties is to handle HTTP Proxies.
# By default, Java uses "http.proxy*" properties to configure HTTP proxies, but
# the "java.net.useSystemProxies" option can be enabled to improve the use of
# system-configured proxy settings based on your platform. If this setting does
# not work for your proxy server setup, try disabling this setting by commenting
# it out and enabling the other settings. See also this information on proxy
# setup:
#
# http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
#
# NOTE: If you find that you need to adjust these settings, you may want to do
# so in a "sencha.cfg" file one folder above this folder. The settings in that
# file override these settings, so be sure to only copy the settings you need
# to that location. The advantage to putting these settings in that location is
# that they will not be "lost" as you upgrade Cmd.

system.java.net.useSystemProxies=true

# These are the legacy options that come in to play when the above is commented
# out:
#system.http.proxyHost=proxy.mycompany.com
#system.http.proxyPort=80
#system.http.proxyUser=username
#system.http.proxyPassword=password

#------------------------------------------------------------------------------
# Merge Tool Settings
#
# To enable use of a visual merge tool to resolve merge conflicts, set the
# following property to the desired merge tool path:
#
#       cmd.merge.tool=p4merge
#
# Next, to configure the arguments for the merge tool, set this property:
#
#       cmd.merge.tool.args={base} {user} {generated} {out}
#
# Alternatively, the arguments for several merge tools are defined below and can
# be used in your configuration for simplicity/clarity like so:
#
#       cmd.merge.tool.args=${cmd.merge.tool.args.sourcegear}
#
# NOTE: the cmd.merge.tool.args property is split on spaces *then* the tokens
# are replaced by actual files names. This avoids the need to quote arguments to
# handle spaces in paths.
#
# NOTE: Some merge tools (like SmartSynchronize) do not accept the output file
# separately so there is no way to know if the merge was completed. In this case,
# the base file is where the result is written so Cmd just copies the content of
# that file back as the result.
#
# You can add the appropriate lines to customize your Cmd configuration. See
# below for details.

# The arguments for p4merge, see below for download:
# http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools
cmd.merge.tool.args.p4merge={base} {user} {generated} {out}

# SourceGear (http://www.sourcegear.com/diffmerge/index.html)
cmd.merge.tool.args.sourcegear=--merge --result={out} {user} {base} {generated}

# kdiff3 (http://sourceforge.net/projects/kdiff3/files/kdiff3/)
cmd.merge.tool.args.kdiff3={base} {user} {generated} -o {out}

# Syntevo SmartSynchronize 3 (http://www.syntevo.com/smartsynchronize/index.html).
cmd.merge.tool.args.smartsync={user} {generated} {base}

# TortoiseMerge (part of TortoiseSVN - see http://tortoisesvn.net).
cmd.merge.tool.args.tortoise=-base:{base} -theirs:{generated} -mine:{user} -merged:{out}

# AraxisMerge (see http://www.araxis.com/merge-overview.html):
cmd.merge.tool.args.araxis=-wait -merge -3 -a1 {base} {user} {generated} {out}

# The address where Sencha Inspector is located
inspector.address=http://localhost:1839/

# this variable references a json file containing unicode code points to be
# printed in escaped form during code generation.
cmd.unicode.escapes=${cmd.dir}/unicode-escapes.json

#------------------------------------------------------------------------------
# Customizing Configuration
#
# Customization can be handled any of these ways:
#
#   1. Place customizations in this file (ideally at the bottom) and they will
#      configure this instance of Sencha Cmd.
#
#   2. Create a "sencha.cfg" file in the folder above this instance of Sencha Cmd
#      to be shared by all installed versions.
#
#   3. Create a "~/.sencha/cmd/sencha.cfg" file. On Windows, the "~" maps to your
#      %HOMEDRIVE%%HOMEPATH% folder (e.g., "C:\Users\Me").
#
# Your personal settings take priority over common settings (item #2) which both
# take priority of instance settings (this file).

谢谢

推荐答案

我想您也正在按照指南进行操作,并使用sencha应用程序监视程序并使php代码返回给您.我在一个Sencha论坛上找到了这个答案,即sencha cmd提供的Web服务器不支持php只是一个基本的HTTP Web服务器.

I guess you are also following the guide and using the sencha app watch and getting the php code returning back to you. I found this answer on a Sencha forum that the web server that the sencha cmd provides doesn't support php is just a basic HTTP web server.

这篇关于ExtJS PHP/MySQL后端连接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆