Laravel 4 数据表集成

Laravel 4 Datatable Integration

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

这是我用来生成数据的htmltabletables:

<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}}

我的代码有问题吗? 感谢您的帮助。

正在查看错误消息中的文件 (View on github) you can see that it's just a short array syntax added in PHP 5.4。这是一个示例:

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

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