首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JsGrid和laravel

JsGrid和laravel
EN

Stack Overflow用户
提问于 2018-09-23 20:29:17
回答 1查看 1.4K关注 0票数 0

我是JsGrid的新手,我正在尝试用laravel编写一些函数,比如https://www.webslesson.info/2018/08/live-table-add-edit-delete-using-php-with-jsgrid-plugin.html。但是我得到了一个错误,显示未定义索引: id。我正在尝试使用json从数据库中调用数据,并将其填充到jsgrid中,但失败了。很抱歉我是个菜鸟。如果我错了,请纠正我。

这是我的jsgrid.js

代码语言:javascript
复制
$("#validation").jsGrid({
width: "100%",
filtering: true,
editing: true,
inserting: true,
sorting: true,
paging: true,
autoload: true,
pageSize: 15,
pageButtonCount: 5,
autosearch: true,
deleteConfirm: "Do you really want to delete the client?",
controller: {
  loadData: function(filter){
      return $.ajax({
          type: "GET",
          url: "../../../api/users",
          data: filter,
          dataType: "JSON"
      });
  }  
},
fields: [
    { 
        name: "Id", 
        type: "text", 
        width: 30
    },
    { 
        name: "Name", 
        type: "text", 
        width: 150, 
    },
    { 
        name: "Email", 
        type: "text", 
        width: 150
    },
    { 
        name: "Password", 
        type: "text", 
        width: 150, 
    },
    { 
        name: "Created at", 
        type: "text", 
        width: 150
    },
    { 
        name: "Married", 
        type: "checkbox", 
        title: "", 
        width: 30,
        sorting: false 
    },
    { 
        type: "control" 
    }
]

});

这是我的控制器

代码语言:javascript
复制
public function ap_index(User $users)
{
    $connect = mysqli_connect("localhost", "root", "", "DCAPT");
    $method = $_SERVER['REQUEST_METHOD'];
    if($method == 'GET')
    {
        $data = array (
            ':Id'   => "%"  .   $_GET['id'] . "%", <------- //The error is here Undefined Index: id
            ':Name'   => "%"  .   $_GET['name'] . "%",
            ':Email'   => "%"  .   $_GET['email'] . "%",
            ':Password'   => "%"  .   $_GET['password'] . "%",
            ':Created_at'   => "%"  .   $_GET['created_at'] . "%"
        );

        $query = "select * from users where id like :Id or name like :Name or email like :Email
                  or password like :Password or created_at like Created_at";

        $statement = $connect->prepare($query);
        $statement = execute($data);
        $result  = $statement->fetchAll();
        foreach($result as $row){
            $output[] = array(
                'Id'        => $row['id'],
                'Name'      => $row['name'],
                'Email'     => $row['email'],
                'Password'  => $row['password'],
                'Created at'=> $row['created_at']
            );
        }
        echo json_encode($output);
    }
}   
EN

回答 1

Stack Overflow用户

发布于 2018-09-23 20:54:34

检查您的MySQL查询:

代码语言:javascript
复制
"select * from users where id like :Id or name like :Name or email like :Email
                  or password like :Password or created_at like Created_at"

您应该在搜索参数中添加'‘:

代码语言:javascript
复制
'...where id like '".$data[':Id']."'...'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52466105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档