Hi everyone, I don’t know if this post fits better here or in an ExtJS forum.
I’m developing a web application using ExtJS for the views and Yii framework (my favorite) to manage interactions with the server.
I have in the ExtJS part:
- a model User (4 properties)
- a store Users with a Ext.data.proxy.Ajax with the following configuration
proxy : {
type: 'ajax',
api:{
create: 'index.php/user/create',
read: 'index.php/user/index',
update: 'index.php/user/update',
destroy: 'index.php/user/delete',
},
actionMethods: {
create: 'POST',
read: 'GET',
update: 'POST',
destroy: 'POST'
},
And in the Yii part I generated a webapp application. Then generated the model and CRUD for the User table in database and finally modified the UserController way of returning data so, instead of rendering views, echoes CJSON::encoded data.
This works perfect!!!.
But ExtJS has another type of proxy: Ext.data.proxy.Rest and the main feature of this one is the methods used for its actions
create: POST
read: GET
update: PUT
destroy: delete
So I configured my new proxy:
proxy : {
type: 'rest',
url: 'index.php/usuario', //all the actions requests this url
//the actions methods are unnecesary
}
I saw a example with Silex and I liked the routing style so I’m trying to emulate it. With this in mind I configured the urlManager of the Yii application to handle the RESTful URL:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
array('user/index', 'pattern'=>'user', 'verb'=>'GET'),
array('user/update', 'pattern'=>'user/<id:\d+>', 'verb'=>'PUT'),
array('user/delete', 'pattern'=>'user/<id:\d+>', 'verb'=>'DELETE'),
array('user/create', 'pattern'=>'user', 'verb'=>'POST'),
),
),
So, with just configuring the url in the proxy I delegate the routing to the urlManager. All is well!
But MY PROBLEM is that in actionCreate the $_POST variable, where the new user data should be is totally empty. Firebug reports that a ‘User’ named variable was posted.
Searching in an example of ExtJS I found this code:
$raw = ‘’;
$httpContent = fopen(‘php://input’, ‘r’);
while ($kb = fread($httpContent, 1024)) {
$raw .= $kb;
}
$params = json_decode(stripslashes($raw));
And the data is in $params but I don’t want to uglify my Gii auto generated code with this. I want to find the data in $_POST as always.
Any suggestions?
Sorry the long post but I wanted to give all the details I could.