Javascript 通过php在datatable编辑器中保存创建的行

Javascript 通过php在datatable编辑器中保存创建的行,javascript,zend-framework2,jquery-datatables,jquery-datatables-editor,Javascript,Zend Framework2,Jquery Datatables,Jquery Datatables Editor,我使用datatable编辑器来显示行 这是我正在使用的代码 var editor; $(document).ready( function () { editor = new $.fn.dataTable.Editor( { "ajaxUrl": { "create": "admin/save", }, "domTable": "#example",

我使用datatable编辑器来显示行

这是我正在使用的代码

var editor; 
$(document).ready( function () {
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": {
                    "create":        "admin/save",

                },
                "domTable": "#example",
                "fields": [ {
                        "label": "username:",
                        "name": "username"
                    }, {
                        "label": "password:",
                        "name": "password",
                        "type":"password"
                    }, {
                        "label": "fname:",
                        "name": "fname"
                    }, {
                        "label": "lname:",
                        "name": "lname"
                    }, {
                        "label": "email:",
                        "name": "email"
                    },{
                        "label": "address:",
                        "name": "address"
                    }
                ]
            } );

            $('#example').dataTable( {

                "sDom": "Tfrtip",

                        "aoColumns": [
                        { "mData": "username"},
                        { "mData": "password" },
                        { "mData": "fname" },
                        { "mData": "lname" },
                        { "mData": "email" },
                        { "mData": "address" }
                    ],

                "oTableTools": {
                    "sRowSelect": "single",
                    "aButtons": [
                        { "sExtends": "editor_create", "editor": editor },
                        { "sExtends": "editor_edit",   "editor": editor },
                        { "sExtends": "editor_remove", "editor": editor }
                    ]
                }
            } );
        } );
如何将表单数据传递到控制器页面。我还提供了名称字段,但它未添加到元素中。 创建:管理/保存 这里admin是控制器名称,save是操作名称


请帮助我。

使用带有编辑器扩展的Datatables,它将数据发送到服务器进行处理。客户端发送三个字段:
action
id
data
。操作可以是
创建
编辑
删除
。该id仅用于
编辑

简而言之,您可以使用此控制器:

<?php
namespace MyModule\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;

class DatatablesController extends AbstractActionController
{
    public function saveAction()
    {
        if (!$this->getRequest()->isPost()) {
            $response = $this->getResponse();
            $response->setStatusCode(405); // Method not allowed
            return $response;
        }

        $action = $this->params()->fromPost('action', null);
        $data   = array();
        switch ($action) {
            case 'create':
                $data = $this->createRow();
                break;
            case 'edit':
                $data = $this->editRow();
                break;
            case 'delete':
                $data = $this->deleteRow();
                break;
            default:
                $response = $this->getResponse();
                $response->setStatusCode(422); // Unprocessable entity
                return $response;
        }

        $model = new JsonModel($data);
        return $model;
    }

    protected function createRow()
    {
        $data = $this->params()->fromPost('data', array());

        // Create a new entity with $data

        // Return the properties from the new entity
        return array();
    }

    protected function editRow()
    {
        $id   = $this->params()->fromPost('id');
        $data = $this->params()->fromPost('data', array());

        // Fetch the entity with id $id
        // Update the entity with $data

        // Return the properties from the entity
        return array();
    }

    protected function deleteRow()
    {
        $ids = $this->params()->fromPost('data', array());

        // Remove all entities with an id in the array $ids
    }
}