doushui3061 2013-03-04 19:55
浏览 54
已采纳

javascript或php中的“状态”?

I've been working with FLEX for while and I had there some "states" declaration. For those who are not sure what I mean, it's like a couple of different pages between you can translate, setting a current state.
Now I want to get started with Facebook development, and I don't know how to pass between pages I created with html. I guess that would be possible using javascript rather than php, but I am not sure how. Can someone please help me?

A scheme of what I would like to do is:

              tigger1  
State A-------------------->State B

              trigger2      
State B-------------------->State C

The following example shows a login panel with 2 states: default, for showing the login form, and Register for showing the form for registration. The current state change is triggered by an action (in this case, pressing the Linkbutton). Mainly, what states do, is displaying proper content based on what the user should be able to do under each state. So, if for example I want to do a payment form, after the user attempts to make the payment, if the payment was successfully done, I would have a "Thank_you" state, while if the payment failed, I would have a "Try_again" state. How can this be done using php/js?

Code sample of login/register panel (from adobe flex website, also running example and full code can be found in the link):

<!-- The Application class states property defines the view states.-->
<s:states>
    <s:State name="default"/>    
    <s:State name="Register"/>
</s:states>

<!-- Set title of the Panel container based on the view state.-->
<s:Panel id="loginPanel" 
    title="Login" title.Register="Register">     

    <s:Form id="loginForm">
        <s:FormItem label="Username:">
            <s:TextInput/>
        </s:FormItem>
        <s:FormItem label="Password:">
            <s:TextInput/>
        </s:FormItem>


        <s:FormItem id="confirm" label="Confirm:" includeIn="Register">
            <!-- Add a TextInput control to the form ONLY for the Register view state. -->           
            <s:TextInput/>
        </s:FormItem>            

        <s:FormItem>            
            <!-- Use the LinkButton to change view state.-->
                <!-- Set label of the control based on the view state.-->
                <mx:LinkButton id="registerLink"
                    label="Need to Register?" 
                    label.Register="Return to Login"
                    click="currentState="Register"
                    click.Register="currentState="default"/>
                <s:Button id="loginButton" 
                    label="Login" label.Register="Register"/>
        </s:FormItem>            
    </s:Form>
</s:Panel>

Thanks in advance

  • 写回答

1条回答 默认 最新

  • drux41001 2013-03-04 20:33
    关注

    Right, I think I understand your question. Flex (or Flash) works with ongoing variables (or states) because it is a long-running program, controlled by events from a user interface.

    Web programming isn't like that. Each page is served separately, from a program that lives only for the duration of that request, and so state has to be maintained on the client side by the use of cookies. Since the server often needs to be aware of user state, the cookie (if one is set) is supplied by the browser to the server automatically, who can cross-reference the cookie's value with things that this user has done before.

    If the cookie value is unique, it can be used to cross-reference a session store, which is a set of values just for one user. PHP offers this inside its $_SESSION feature. This is quite a big topic in itself, so I would recommend web-searching for "PHP session examples" - here and on the web - and playing with some code. Real examples will show you how it all works.

    Edit: turns out states (variables) and states (UI variants) are different things! See the comments for more details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路