2016-08-05 3 views
1

私のフォーム検索用のdataTableを探してsolarisを使ってApache solrから結果を得るために探しています。PHPのクライアントと各結果について、以下のようなJSON形式に変換します:in自分の行動の検索:私はずっとこのfuctionの中のURLを表示するJSONファイルを送信することができますどのようにcakephp2.6のdataTableにjsonファイルを送る方法

public function search() { 
    if($_POST){ 
    // get a select query instance 
      $query = $client->createSelect() 
        ->setQuery($forsearch) 
        ->addParam('wt','json'); 
    // this executes the query and returns the result 
       $resultset = $client->select($query); 

       $this->response->body(json_encode($result)); 
    } 
    } 

$('.datatable-ajax-source table').dataTable({ 
       "processing": true, 
       "serverSide": true, 
       "ajax": { 
       "url": "http://localhost/solr/users/search.json", 

      }); 

私はの$ this - を使用しカント> falseを自動レンダリング=;私はsearch.ctpから$ resulsetを得るためにinput forarchを入力する必要があるので

答えて

0

This link私の場合はverry有用です。この質問は近いです。みなさん、ありがとう。

0

Ello、mate。コントローラ機能で は、あなたがインデックス「データ」を持つオブジェクトへの応答をフォーマットする必要があり、そのインデックスはDataTableのことで表示されるリストを含むリストが含まれている必要があり、それは次のようになります。

{ 
    data: [ 
     [field, field, field, field], 
     [field, field, field, field]........ 
    ] 
} 

あなたのケースでは、フィールドをimplode()するのを忘れないでください。フィールドを 'competence_txt'にimplode()して文字列にする必要があります。

詳細はDatatables oficial websiteを確認してください。

+0

ありがとうございます。私はすでに静的なjsonファイルでテストし、データテーブルhesのコンテンツを表示します。今私はgenarate自動的にデータテーブルに送信するjsonファイルを探しています。 – MedKostali

+0

** $ response ** =あなたの応答を考慮すると、データ型が読むことができるjsonにフォーマットする必要があります。 試してみてください: '$ arr_response = json_decode($ response、true); $ arr_data = array( 'data' => array()); foreachの($ $キー=> $ valのように[ '応答'] [ 'ドキュメントを'] arr_response) {\t $ this_data =配列(); \t if(is_array($ val)) \t { \t \t $ imploded_val = implode( '、'、$ val); \t \t array_push($ this_data、$ imploded_val);他 \t {\t \t array_push($ this_data、$ val)で \t} \t。 \t \t \t array_push($ arr_data ['data']、$ this_data); } echo json_encode($ arr_data); ' –

関連する問題