0
  1. 请帮助我使用带有 codeigniter 控制器的示例剑道网格

    我的观点

    $("#grid").kendoGrid({
    dataSource: {
        transport: {
            read: {
                url: 'schoolC/crud',
                contentType: 'application/json'
            },
            create: {
                url: 'schoolC/crud',
                type: "PUT",
                datatype: 'json'
            },
            update: {
                url: 'schoolC/crud',
                type: "POST",
                datatype: 'json'
            },
            destroy: {
                url: 'schoolC/crud',
                type: "POST",
                datatype: 'json'
            }                                
        },
        error: function(e) {
                alert(e.responseText);
            },
        schema: {
            data: "data",
            id: "school_id",
            model: {
                fields: {
                    school_name: { 
                        type: "string",
                        validation: { required: true }
                    }
                }
            }
        },
        pageSize: 10
    },
    height: 400,
    batch: false,
    scrollable: true,
    sortable: true,
    filterable: true,
    resizable: true,
    toolbar: ['create'],
    editable: "popup",
    pageable: {                            
        numeric: true,
        refresh: true,
        pageSizes: true
    }, 
    columns: [
        {
            field: "school_name",
            title: "School Name",                                
            width: 100
        },
        { command: ["edit", "destroy"], title: " ", width: "210px" }                            
    ]
    

    });

    控制器方法

    function crud()
    {
        header("Content-type: application/json");
        switch($_SERVER["REQUEST_METHOD"])
        {
            case 'GET':
                echo $this->SchoolM->get_allJsonData(); 
            break;
            case 'PUT':
                echo $this->SchoolM->addSchoolInfo(array('school_name'=> mysql_real_escape_string($_POST["school_name"])));
            break;
            case 'POST':
                echo $this->SchoolM->updateSchoolInfo(array('school_name'=> mysql_real_escape_string($_POST["school_name"])), array('school_id'=> mysql_real_escape_string($_POST["school_id"])));
            break;
            case 'DELETE':
                echo $this->SchoolM->deleteSchool(mysql_real_escape_string($_POST["school_id"]));               
            break;
        }
    }
    

    模型方法

    function get_allJsonData()
    {
        $arr = array();
        $this->db->from('school');
        $this->db->order_by("school_name", "asc");
        $query = $this->db->get();
        foreach($query->result_object() as $rows )
        {
            $arr[] = $rows;
        }
        return "{\"data\":" .json_encode($arr). "}";
    }
    function addSchoolInfo($school_name)
    {
        return json_encode($this->db->insert('school',$school_name));
    } 
    function updateSchoolInfo($school_date, $condition)
    {
        return json_encode($this->db->update('school', $school_date, $condition));
    }
    function deleteSchool($school_id)
    {
        $this->db->where_in('school_id',$school_id);
        return json_encode($this->db->delete('school'));
    }   
    

    我正在使用它读取的codeigniter,但其余的创建更新和删除无法正常工作。它还添加了许多空行作为每个创建操作中行的大小。请帮助我

4

1 回答 1

0

抱歉不懂英语,自动翻译这个工作在这里,大声笑。但我想我可以帮助你,你正在努力在你的 GRID 中拨打他们的电话 CRUD?

我所做的是使用相同的调用创建所有内容,但如果通过引用传递将要完成的操作,则使用 GET。请参见下面的示例。

$("#grid").kendoGrid({
        dataSource: {
            transport:{
                read: "CRUD.client.php?func=read",
                create: {
                    url: "CRUD.client.php?func=create",
                    type: "POST"
                },
                update: {
                    url: "CRUD.client.php?func=update",
                    type: "POST"
                },
                destroy: {
                    url: "CRUD.client.php?func=delete",
                    type: "POST"
                }
            },

请注意,一旦文件对所有人都相同,具有传递参数,php 将读取并通过 if 决定谁将执行警报。

if ($verb == "GET" && $func == "read") {code CRUD here}

我有帮助!!!

于 2013-06-06T12:23:32.753 回答