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 (name, value) {
var me = this;
if (typeof value === "undefined" || value === null) {
me.clear(name);
return;
}
me.setValue(name, value);
this.callParent(arguments);
},
clear: function (name) {
this.clearValue(name);
this.callParent(arguments);
},
readValues: function () {
var me = this;
Ext.Ajax.request({
url: me.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 (name, value) {
var me = this;
Ext.Ajax.request({
url: me.managerScript,
params: {
action: 'set',
name: name,
value: me.encodeValue(value)
},
method: 'POST',
success: function (response) {},
failure: function () {
// Your way to treat errors
}
});
},
clearValue: function (name) {
var me = this;
Ext.Ajax.request({
url: me.managerScript,
params: {
action: 'clear',
name: name
},
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 