keign ui grid crud with codeigniter

时间:2013-05-22 16:34:05

标签: php codeigniter kendo-grid

  1. 请求帮我使用带有codeigniter控制器的示例kendo网格

    我的观点

    $("#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,但其余的创建更新和删除都没有正常工作。它还添加了许多空行作为每个create operation.pls中行的大小帮助我

1 个答案:

答案 0 :(得分: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}

我帮了!!!