如何使用数据服务绑定flex 4.5中的查询结果 - PHP / mySQL / Flex 4.5

时间:2014-02-12 01:06:45

标签: php mysql flex flex4.5

我正在尝试将变量与通过以下PHP脚本执行的查询结果绑定在一起:

<?php

//conection info
define("DATABASE_SERVER", "localhost");
define("DATABASE_PORT", "3306");
define("DATABASE_USERNAME", "root");
define("DATABASE_PASSWORD", "root");
define("DATABASE_NAME", "e5001");

class EsporteService
{
    private $_pdo;

    public function __construct() {
        try {
            $this->_pdo = new PDO('mysql:host='.DATABASE_SERVER.';port='.DATABASE_PORT.';dbname='.DATABASE_NAME, DATABASE_USERNAME, DATABASE_PASSWORD);

        } catch(PDOException $e) {
            throw($e);
        }
    }


    /**
     * 
     * @return array[Esporte]
     */
    public function getEsportes()
    {
        $query = 'SELECT * FROM esporte_tb';            
        $stmt = $this->_pdo->query($query);
        return $stmt->fetchAll(PDO::FETCH_CLASS,'Esporte');
    }
}

mxml片就是这个:

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:consultaservice="services.consultaservice.*"
        xmlns:esporteservice="services.esporteservice.*"
        title="HomeView" creationComplete="view1_creationCompleteHandler(event)">
    <fx:Script>

        <![CDATA[
            import mx.events.FlexEvent;

            protected function view1_creationCompleteHandler(event:FlexEvent):void
            {
                getEsportesResult.token = esporteService.getEsportes();
            }

        ]]>
        </fx:Script>
    <fx:Declarations>
        <s:CallResponder id="getEsportesResult"/>
        <esporteservice:EsporteService id="esporteService"/>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:VGroup x="10" y="10" width="100%" height="100%" horizontalAlign="center">
        <s:Image x="100" width="179" height="125" source="assets/spadotto_logo.jpg"/>
        <s:List id="list" height="40%" 
                dataProvider="{getEsportesResult.lastResult}"
                labelField="esp_desc"
                change="navigator.pushView(TreinosDetails, list.selectedItem)"/>
        <s:Label id="teste" />

    </s:VGroup>
</s:View>

我尝试了很多不同的方法,创建一个可绑定的变量,如Array,ArrayCollection,Object等,但是无法使它工作。

我正在尝试解析查询并获取其长度,基于标签“teste”是否可见。

有什么想法吗?

非常感谢,

吉恩斯

0 个答案:

没有答案