0

I have the following question. How can I select a php file as source in my fx model connection.

I want to use in my fx model source a php file that returns an xml file. Is this possible?

Now I have tried to work with an http service to read the php file on running and with an xmllistcollection. This is my code:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           xmlns:components="components.*">

<s:layout>
    <s:VerticalLayout paddingTop="20" gap="20" 
                      horizontalAlign="center" />
</s:layout>
<fx:Script>
    <![CDATA[
        import mx.rpc.events.ResultEvent;
        import mx.collections.ArrayCollection; 
        import mx.collections.XMLListCollection; 

        import mx.rpc.events.FaultEvent;
        import mx.controls.Alert;
        private var alert:Alert;

        private function httpService_fault(evt:FaultEvent):void {
            var title:String = evt.type + " (" + evt.fault.faultCode + ")";
            var text:String = evt.fault.faultString;
            alert = Alert.show(text, title);
            Bezoekers.removeAll();
        }

        private function httpService_result(evt:ResultEvent):void {
            var xmlList:XMLList = XML(evt.result).bezoekers.bezoeker;
            Bezoekers = new XMLListCollection(xmlList);
        }
    ]]>
</fx:Script>
<fx:Declarations>
    <s:HTTPService id="httpService"
                   url="http://localhost/projectnieuw/src/data/bezoekersList.php"
                   resultFormat="e4x"
                   fault="httpService_fault(event);"
                   result="httpService_result(event)" />
    <!--<fx:Model id="lijstAlleLeden" source="httpAlleLeden" />-->
    <!--<s:ArrayCollection id="acBezoekers" source="{Bezoekers}"/>-->
    <s:XMLListCollection id="Bezoekers"/>
</fx:Declarations>

<components:Heading/>
<s:HGroup gap="50">

    <components:BezoekersList bezoekerList="{Bezoekers}" />
    <components:ReservationForm/>

</s:HGroup>

</s:Application>

I don't get any errors but I don't see any information in my list.

Mark Fox
  • 8,694
  • 9
  • 53
  • 75

1 Answers1

3

If I understand what you want to do; then you can't do it. The Model tag is a compile time value. That model data is, in essence, embedded into our SWF at compile time. Whereas the PHP script would execute at runtime. Even if Flex would embed the PHP file; it would be using the PHP Code and not the results you get when executing the PHP Code.

I would recommend looking into loading the data from the PHP script at runtime. There are plenty of ways to do this; depending what your PHP Script returns. If you want to load it using an HTTP Get Request; I would recommend using HTTPService. If you can make use of something AMF related, such as with AMFPHP or ZenAMF then I would use RemoteObject.

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
  • I have inserted a http service to load the php script at runtime. But it still doesn't work. I try put the xml information into an arraycollection.This is my service function and this is the function I use to create the arraycollection: private function getDataResultHandler(event:ResultEvent):void { Bezoekers = new ArrayCollection(event.result.bezoekers.bezoeker) } – user1941525 Jan 01 '13 at 22:54
  • Try converting the XML as an XMLListCollection. At this point, you may consider editing this question or posting a new question. Probably the latter; as "How do I get this data" is a different question than "how do I process this data." Either way; you should quantity "Does not work". Are you getting runtime errors? Or compile time errors? Or unexpected behavior? – JeffryHouser Jan 01 '13 at 22:59
  • Yes I'm sorry, I should have edited my question. I'm now trying a tutorial where there is a converting as an xmllistcollection. – user1941525 Jan 01 '13 at 23:10
  • 1
    I very very strongly recommend you put your question back to the way it was and post a new question. You have, in essence, removed the old question completely; making this answer seem out of place. – JeffryHouser Jan 02 '13 at 01:05
  • I edited the question. I shall post a new question with my current question. I'm sorry for the inconvenience. – user1941525 Jan 02 '13 at 01:23
  • Here is the url to my new question: http://stackoverflow.com/questions/14115940/httpservice-and-xmllistcollection7 – user1941525 Jan 02 '13 at 01:29