开发者

Can default Symfony form-save actions be used to post data via AJAX?

开发者 https://www.devze.com 2022-12-31 02:34 出处:网络
I was playing around with Symfony, jQuery, jqGrid & AJAX. For each new p开发者_Go百科ost submission, I am doing the foll:

I was playing around with Symfony, jQuery, jqGrid & AJAX. For each new p开发者_Go百科ost submission, I am doing the foll:

  1. adding a routing entry in routing.yml
  2. defining a new action in the Actions file for the module. THis reads params, assigns values & saves the object

As in the case of jqGrid, the 'Add Row' form is not a Symfony form. Is there a way to fool Symfony and post data to the executeCreate action to store a new entry.

If not, does Symfony provide a way to quickly generate web services for AJAX requests for each of the modules? Is this a sensible feature?

What I am going to have to do other-wise, is to

  • create routing
  • create a new Action
  • get all parameters
  • instantiate object
  • assign values & save

Any help in doing this faster will be appreciated. Thanks in advance


To avoid creating a new route each time, you could create a single ajax action which redirects your requests to the correct part of the app.

Just create an action which takes an extra parameter called 'action', then forward the request.


If you use commercial jqGrid version for PHP which available for $299 (see http://www.trirand.net/forum/default.aspx?g=posts&t=200) then you should just make a question in the corresponding support forum (see http://www.trirand.net/forum/default.aspx?g=posts&t=200 as an example). If you use a free version of jqGrid, then probably you should just try sfAlyssaJqGridPlugin (see http://www.symfony-project.org/plugins/sfAlyssaJqGridPlugin) or ysJQueryUIPlugin (see http://trac.symfony-project.org/browser/plugins/ysJQueryUIPlugin and http://www.celalo.com/integrating-jqgrid-with-symfony-propel/).

I am not use Symfony myself. In general you can integrate in jqGrid any web server providing pure data either in JSON (the best way) or XML format, but you should know there ajax possibilities. If sfAlyssaJqGridPlugin and ysJQueryUIPlugin will not solve your problem, you should clear how you can do following actions in pure JavaScript/jQuery:

  1. Get the data from the server which should be displayed inside of jqGrid. jqGrid can gives to server additional information about sorting, paging and filtering of data selected on the client side by the user who use jqGrid. This information will be added as parameter to URL user for server requests or can be send to server in other way (there are a lot of customization possibility in jqGrid).
  2. Modify the data (a row of data) displayed in jqGrid
  3. Add new data (a row with the new data) which will be displayed in jqGrid
  4. Delete the data (a row of data) displayed in jqGrid

All of these actions can be customized in jqGrid, so for the beginning a small JavaScript using jQuery.ajax and no jqGrid for all this actions will be enough. Then I could help you to realize these actions inside of jqGrid.

0

精彩评论

暂无评论...
验证码 换一张
取 消