我想在Laravel中使用Kendo UI。这是工作很好,而我不想做一个CRUD的东西。在Telerik UI(Kendo)包中包含使用PHP封装CRUD函数的工作示例,但是我无法正确使用Laravel框架实现它。 (只显示空的网格。)在控制器的第一部分,当请求是'POST'并且取决于参数使某些CRUD内容时创建一个json内容。第二部分创建网格和后面的DataSourceTransport(等),以及称为'POST'请求的URL。该路线调用'任何'路线(路线\ web.php),但无法正常工作。我想象的路线设置是坏的,但我不知道什么是解决方案。 (我公司签订 “// !!!!!!!!!!!!!!!!!” 的问卷调查部分)Laravel和Kendo UI Grid:在网格编辑功能中路由URL请求CRUD json
GjtorzsXController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
class GjtorzsXController extends Controller
{
//
public function index()
{
$result = new \DataSourceResult('sqlite:../database/database.sqlite');//
//1st section----------------------------------------------------------
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
header('Content-Type: application/json');
$request = json_decode(file_get_contents('php://input'));
$type = $_GET['type'];
$columns = array('Rendszam', 'Tipus');
switch($type) {
case 'create':
$result = $result->create('gepjarmu', $columns, $request->models, 'id');
break;
case 'read':
$result = $result->read('gepjarmu', $columns, $request);
break;
case 'update':
$result = $result->update('gepjarmu', $columns, $request->models, 'id');
break;
case 'destroy':
$result = $result->destroy('gepjarmu', $request->models, 'id');
break;
}
echo json_encode($result);
exit;
}
//2nd section------------------------------------------------------
$transport = new \Kendo\Data\DataSourceTransport();
$create = new \Kendo\Data\DataSourceTransportCreate();
$create->url('gjtorzsx?type=create')
->contentType('application/json')
->type('POST');
$read = new \Kendo\Data\DataSourceTransportRead();
$read->url('gjtorzsx?type=read') //TestPage.php?type=read gjtorzsx?type=read
->contentType('application/json')
->type('POST');
$update = new \Kendo\Data\DataSourceTransportUpdate();
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//This url is not correct??????????????????????
$update->url('gjtorzsx?type=update') //????????????????????????????
->contentType('application/json')
->type('POST');
$destroy = new \Kendo\Data\DataSourceTransportDestroy();
$destroy->url('gjtorzsx?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();
$rendszamField = new \Kendo\Data\DataSourceSchemaModelField('Rendszam');
$rendszamField->type('string');
$tipusField = new \Kendo\Data\DataSourceSchemaModelField('Tipus');
$tipusField->type('string');
$model->id('id')
->addField($rendszamField)
->addField($tipusField;
$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');
$rendszamColumn = new \Kendo\UI\GridColumn();
$rendszamColumn->field('Rendszam')
->title('Rendszám')
->width(100);
$tipusColumn = new \Kendo\UI\GridColumn();
$tipusColumn->field('Tipus')
->title('Típus')
->width(200);
$command = new \Kendo\UI\GridColumn();
$command->addCommandItem('destroy')
->title(' ')
->width(150);
$grid->addColumn($rendszamColumn, $tipusColumn, $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);
$args = array('grid' => $grid);
return \View::make('hello2')->with($args);
}
}
路径\ web.php:
Route::any('gjtorzsx', '[email protected]');
helo2.blade.php: ... {! $ grid-> render()!!} ...
任何错误信息?检查你的日志。你可以将其修改为https://stackoverflow.com/help/mcve吗? – Robert
没有错误消息,只有网格是空的。我检查日志和错误是在路线url:'TokenMismatchException in VerifyCsrfToken.php line 68'我尝试解决方案:'“>”但不起作用... –