1. #1
    Sencha User
    Join Date
    Dec 2011
    Location
    Poitiers, France
    Posts
    20
    Vote Rating
    3
    youss.imzourh is on a distinguished road

      1  

    Default PHP Session State Provider

    PHP Session State Provider


    Hi there,


    To avoid getting "400 Bad Request" on client side because the cookies that contains the components states is are full (too long), You can use this extension for php applications:


    ExtJS Class that extends Ext.state.Provider (like Ext.state.CookieProvider do):
    PHP Code:
    Ext.define('Ext.ux.PhpSessionStateProvider', {
        
    extend'Ext.state.Provider',


        
    constructor: function (config) {
            var 
    me this;


            
    me.managerScript 'data/actions/divers/component_state.php';


            
    me.callParent(arguments);


            
    me.readValues();
        },


        
    set: function (namevalue) {
            var 
    me this;


            if (
    typeof value === "undefined" || value === null) {
                
    me.clear(name);
                return;
            }
            
    me.setValue(namevalue);
            
    this.callParent(arguments);
        },


        
    clear: function (name) {
            
    this.clearValue(name);
            
    this.callParent(arguments);
        },


        
    readValues: function () {
            var 
    me this;


            
    Ext.Ajax.request({
                
    urlme.managerScript,
                
    params: {
                    
    action'read'
                
    },
                
    method'POST',
                
    success: function (response) {
                    var 
    responseObject;


                    try {
                        
    responseObject Ext.decode(response.responseText);
                        if (
    responseObject && Ext.isArray(responseObject)) {
                            
    Ext.each(responseObject, function (item) {
                                
    me.state[item.name] = me.decodeValue(item.value);
                            });
                        }
                    } catch (
    err) {
                        
    // Your way to treat errors
                    
    }
                },
                
    failure: function () {
                    
    // Your way to treat errors
                
    }
            });
        },


        
    setValue: function (namevalue) {
            var 
    me this;


            
    Ext.Ajax.request({
                
    urlme.managerScript,
                
    params: {
                    
    action'set',
                    
    namename,
                    
    valueme.encodeValue(value)
                },
                
    method'POST',
                
    success: function (response) {},
                
    failure: function () {
                    
    // Your way to treat errors
                
    }
            });
        },


        
    clearValue: function (name) {
            var 
    me this;


            
    Ext.Ajax.request({
                
    urlme.managerScript,
                
    params: {
                    
    action'clear',
                    
    namename
                
    },
                
    method'POST',
                
    success: function (response) {},
                
    failure: function () {
                    
    // Your way to treat errors
                
    }
            });
        }
    }); 

    A little PHP script to show how to treat requests:
    PHP Code:
    require_once('config.inc.php');


    $action array_key_exists('action'$_POST) ? $_POST['action'] : '';
    $stateName array_key_exists('name'$_POST) ? $_POST['name'] : '';
    $stateValue array_key_exists('value'$_POST) ? $_POST['value'] : '';


    if (!
    array_key_exists('states'$_SESSION)) {
        
    $_SESSION['states'] = array();
    }


    switch (
    $action) {
    case 
    'read':
        echo 
    json_encode($_SESSION['states']);
        break;
    case 
    'set': case 'clear':
        if (
    $stateName) {
            if (!
    $stateValue) {
                if (
    array_key_exists($stateName$_SESSION['states'])) {
                    unset(
    $_SESSION['states'][$stateName]);
                }
            } else {
                
    $_SESSION['states'][$stateName] = $stateValue;
            }
        }
        break;
    default:
        echo 
    json_encode(array('code' => 'unknown_action''message' => "Action inconnue."));


    Hope il helps!


    See Ya

  2. #2
    Sencha User B@RT's Avatar
    Join Date
    May 2010
    Posts
    5
    Vote Rating
    0
    B@RT is on a distinguished road

      0  

    Default


    your solution is not optimized...

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Location
    Poitiers, France
    Posts
    20
    Vote Rating
    3
    youss.imzourh is on a distinguished road

      0  

    Default


    I know it' not so.


    I don't have a better solution actually! If you have one, please go ahead and give it to me, I'm waiting for your science, dude

    It's been months that I'm searching for a solution on the net and in my head. I still have a headache because of that!

    See ya!

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar