2016-12-06 7 views
1

Laravelで剣道UIを使用したい。私はCRUDのことをしたいとは思っていませんが、それは良い仕事です。 Telerik UI(剣道)パッケージには、PHPラッパーのCRUD関数の使用例が含まれていますが、Laravelフレームワークで正しく実装することはできません。 (空のグリッドだけを表示します)コントローラーの第1セクションでは、要求が 'POST'のときにjsonコンテンツを作成し、パラメーターに応じてCRUDを行います。 2番目のセクションでは、グリッドと背面のDataSourceTransport(など)と、「POST」リクエストと呼ばれるURLを作成します。ルートは 'any'ルート(route \ web.php)を呼び出しますが、正しく動作しません。私は、ルートの設定が悪いと思いますが、私は解決策が何であるか分かりません。Laravelと剣道UIグリッド:グリッド編集機能で要求する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()!!} ...

+0

エラーメッセージはありますか?ログを確認してください。これをhttps://stackoverflow.com/help/mcveに整理できますか? – Robert

+0

エラーメッセージはありません。グリッドのみが空です。私はログをチェックし、エラーはルートURLにあります: 'TokenMismatchException VerifyCsrfToken.php 68行目です'解決策を試してみます: '"しかし、動作しません... –

答えて

0

このVerifyCsrfToken例外も発生していました。このリンクからの情報は非常に役に立ちました: http://laravel.io/forum/01-30-2015-laravel5-tokenmismatchexception-in-verifycsrftoken/?page=3) 、geethpwの回答を参照してください。具体的には、私は以下の追加をした:

私のHTML文書の上部にある私のメタタグで

、私は

<meta name="csrf-token" content="{{ csrf_token() }}"> 

を追加しました。そして、私はjQueryの宣言の後に私のヘッダーに次のスクリプトを追加しました:

フォームのコンテキストでグリッドが宣言されていないため、私はCSRFトークンを隠しフィールドとして追加しませんでした。

Laracastにも同じ問題を抱えているようですが、私もあなたのコメントを見ました。私はあなたとは少し違ってDataSourceを扱ったことに気づくでしょう。あなたがこの問題に遭遇したら私に知らせて、私がやったことを投稿します。私は他のCRUDアクションの実装を開始していませんが、ついにデータを表示しています。

関連する問題