Laravel 4数据表集成


Laravel 4 Datatable Integration

我是Laravel的新手,我想使用Laravel数据表生成MYSQL数据,我做了如下操作:

这是我用于生成数据表的html表:

<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-condensed table-bordered" id="articles">
 <thead>
    <tr>
        <th>ID</th>
        <th>Code</th>
        <th>Name</th>
        <th>Description</th>
        <th>Created At</th>
        <th>Updated At</th>
    </tr>
</thead>
    <tbody>
    </tbody>
</table> 

这是我的js:

<script type="text/javascript">
$('#articles').dataTable( 
    {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "{{URL::to('arayez/getView')}}",
        "aaSorting": [[ 3, "desc" ]],
        "aoColumns": [
        { 'sWidth': '60px' },
        { 'sWidth': '130px', 'sClass': 'center' },
        { 'sWidth': '180px', 'sClass': 'center' },
        { 'sWidth': '60px', 'sClass': 'center' },
        { 'sWidth': '90px', 'sClass': 'center' },
        { 'sWidth': '80px', 'sClass': 'center' },
        { 'sWidth': '80px', 'sClass': 'center' }
        ]
    }
); 
</script>

这是我的控制器功能:

class Test extends BaseController
{
    public function getView()
    {
        $result = DB::table('module')->select(array('module.id AS id','module.code','module.name','module.description','module.created_at','module.updated_at','module.user_id'));
        return Datatables::of($result)->make();
    }
}

这是我的路线:

Route::group(
    array('prefix' => 'arayez'), 
    function() {
        Route::get('test', 'arayez'Test@getTest');
        Route::get('getView', array('uses'=>'arayez'Test@getView','as'=>'arayezGetView'));
    }
);

这就是错误:

{"error":{"type":"Symfony''Component''Debug''Exception''FatalErrorException","message":"syntax error, unexpected '['","file":"'/var'/www'/auth'/vendor'/bllim'/datatables'/src'/Bllim'/Datatables'/Datatables.php","line":79}}

我的代码有什么问题吗?谢谢你的帮助。

查看错误消息中的文件(在github上查看),您可以看到它只是在PHP 5.4中添加的一个短数组语法。这里有一个例子:

$array = []; // instead of $array = array();

这个错误几乎肯定意味着您的PHP版本早于5.4。解决这个问题的唯一方法是将PHP至少升级到5.4。特别是因为它也是Laravel的一个要求(我相信从4.1版开始)