Telerik PHP剑道UI网格/外键列演示错误

Telerik PHP剑道UI网格/外键列演示错误,php,kendo-ui,telerik,Php,Kendo Ui,Telerik,在仔细地从我的TestPage.php(只是更改数据库连接)中编写代码并使用演示的文件DaraSourceResult.php之后,它仍然出现了两个错误: 1) 当网格呈现时,它从数据库中获取数据,但ForeignKey列为空 2) 如果在“外键”列中单击,它将成功显示数据库中的CategoryNames,但当您选择一个类别时,它不起作用,可能是因为它试图在数字字段中使用文本 我附上了一张照片,上面显示了上述每个bug。下面还有我在TestPage.php中使用的代码 你能帮我修复这两个错误吗

在仔细地从我的TestPage.php(只是更改数据库连接)中编写代码并使用演示的文件DaraSourceResult.php之后,它仍然出现了两个错误:

1) 当网格呈现时,它从数据库中获取数据,但ForeignKey列为空

2) 如果在“外键”列中单击,它将成功显示数据库中的CategoryNames,但当您选择一个类别时,它不起作用,可能是因为它试图在数字字段中使用文本

我附上了一张照片,上面显示了上述每个bug。下面还有我在TestPage.php中使用的代码

你能帮我修复这两个错误吗

非常感谢



我发现了错误。我只是对变量中的列字段名称有问题。它没有使用FKCateriaEntrada,而是尝试使用FKCateria


代码现在运行顺利。如果需要,您可以使用它。

我发现了错误。我只是对变量中的列字段名称有问题。它没有使用FKCateriaEntrada,而是尝试使用FKCateria

代码现在运行顺利。如果需要,你可以使用它

      <?php
    require $_SERVER['DOCUMENT_ROOT'] . '/lib/Kendo/Autoload.php';
    require $_SERVER['DOCUMENT_ROOT'] . '/lib/DataSourceResult.php';
    ?>


    <?php
    $result = new DataSourceResult('mysql:host=localhost;dbname=db', 'user', '******'); //ok


    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        header('Content-Type: application/json');
        $request = json_decode(file_get_contents('php://input'));
        $type = $_GET['type'];
        $columns = array('PKEntrada', 'Descricao', 'Valor', 'FKCategoriaEntrada');
        switch($type) {
            case 'create':
                $result = $result->create('tblentradas', $columns, $request->models, 'PKEntrada');
                break;
            case 'read':
                $result = $result->read('tblentradas', $columns, $request);
                break;
            case 'update':
                $result = $result->update('tblentradas', $columns, $request->models, 'PKEntrada');
                break;
            case 'destroy':
                $result = $result->destroy('tblentradas', $request->models, 'PKEntrada');
                break;
        }
        echo json_encode($result);
        exit;
    }
    ?>


    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <link rel="stylesheet" href="styles/kendo.common.min.css" />
        <link href="styles/kendo.bootstrap.min.css" rel="stylesheet" />


        <script src="js/jquery.min.js"></script>
        <script src="js/kendo.all.min.js"></script>
    </head>
    <body>


<?php
$categories = $result->read('tblcategoriasentrada', array('PKCategoriaEntrada as value', 'Categoria as text'));


$transport = new \Kendo\Data\DataSourceTransport();
$create = new \Kendo\Data\DataSourceTransportCreate();
$create->url('TestPage.php?type=create')
     ->contentType('application/json')
     ->type('POST');
$read = new \Kendo\Data\DataSourceTransportRead();
$read->url('TestPage.php?type=read')
     ->contentType('application/json')
     ->type('POST');
$update = new \Kendo\Data\DataSourceTransportUpdate();
$update->url('TestPage.php?type=update')
     ->contentType('application/json')
     ->type('POST');
$destroy = new \Kendo\Data\DataSourceTransportDestroy();
$destroy->url('TestPage.php?type=destroy')
     ->contentType('application/json')
     ->type('POST');
$transport->create($create)
          ->read($read)
          ->update($update)
          ->destroy($destroy)
          ->parameterMap('function(data) {
          return kendo.stringify(data);
      }');
$model = new \Kendo\Data\DataSourceSchemaModel();
$productIDField = new \Kendo\Data\DataSourceSchemaModelField('PKEntrada');
$productIDField->type('number')
               ->editable(false)
               ->nullable(true);
$productNameField = new \Kendo\Data\DataSourceSchemaModelField('Descricao');
$productNameField->type('string')
                 ->validation(array('required' => true));
$unitPriceValidation = new \Kendo\Data\DataSourceSchemaModelFieldValidation();
$unitPriceValidation->required(true)
                    ->min(1);
$unitPriceField = new \Kendo\Data\DataSourceSchemaModelField('Valor');
$unitPriceField->type('number')
               ->validation($unitPriceValidation);
$categoryIDField = new \Kendo\Data\DataSourceSchemaModelField('FKCategoria');
$categoryIDField->type('number');


$model->id('PKEntrada')
    ->addField($productIDField)
    ->addField($productNameField)
    ->addField($unitPriceField)
    ->addField($categoryIDField);
$schema = new \Kendo\Data\DataSourceSchema();
$schema->data('data')
       ->errors('errors')
       ->model($model)
       ->total('total');
$dataSource = new \Kendo\Data\DataSource();
$dataSource->transport($transport)
           ->batch(true)
           ->pageSize(30)
           ->schema($schema);
$grid = new \Kendo\UI\Grid('grid');
$productName = new \Kendo\UI\GridColumn();
$productName->field('Descricao')
            ->title('Description');
$unitPrice = new \Kendo\UI\GridColumn();
$unitPrice->field('Valor')
          ->format('{0:c}')
          ->width(200)
          ->title('Value');
$categoryID = new \Kendo\UI\GridColumn();
$categoryID->field('FKCategoria')
          ->title('FKCategory')
          ->values($categories['data'])
          ->width(200);
$command = new \Kendo\UI\GridColumn();
$command->addCommandItem('destroy')
        ->title('&nbsp;')
        ->width(150);
$grid->addColumn($productName, $categoryID, $unitPrice, $command)
     ->dataSource($dataSource)
     ->addToolbarItem(new \Kendo\UI\GridToolbarItem('create'),
    new \Kendo\UI\GridToolbarItem('save'), new \Kendo\UI\GridToolbarItem('cancel'))
     ->height(540)
     ->navigatable(true)
     ->editable(true)
     ->groupable(true)
     ->pageable(true);
echo $grid->render();
?>