首页 > 解决方案 > 辅助类中的列排序方法在一个表上工作,但在同一个应用程序中不是另一个表

问题描述

试图弄清楚为什么这个(我认为很简单)功能不起作用。

快速背景,这个应用程序是由另一家公司制作的,我被请来对 ui 和一些功能进行一些更改。我一直在学习这个系统,以及它同时构建的框架(Laravel 5.1)。整个事情都在一个 docker 容器中运行。

表助手类

<?php
namespace App\Helpers;
use Illuminate\Support\Facades\Log;

class TableHelper {
  public static function uriColumnSorter($label, $sort, $color = '#758292') {

    $str = \Request::url();

    //get the variables in the url e.g. sort: col name, direction: asc
    $data = \Input::all();

    //if there is a _url var in the url, unset it
    if (isset($data['_url'])) {
        unset($data['_url']);
    }

    //the column to sort, set to the param passed in
    $data['sort'] = $sort;

    //Either set to desc if direction already exists and is asc, or set to asc
    $direction = $data['direction'] = (isset($data['direction']) && $data['direction'] == 'asc') ? 'desc' : 'asc';

    //build query out of the data array if it has values
    if (count($data) > 0) {
        $str .= '?' . http_build_query($data);
    }

    //throw an a tag back with a link with the sorted query
    echo '<a href="' . $str . '" style="color: ' . $color . '">' . $label . ' <i class="fa fa-sort-alpha-' . $direction . '" aria-hidden="true" style="margin-left: 12px;"></i></a>';
}
}

太好了,您在需要的地方调用它,它会吐出一个基于列对表进行排序的标签。这是在排序工作的地方使用它的一个实例

<table class="table table-striped">
        <thead>
            <tr>
                <th class="col-md-3">{{ \App\Helpers\TableHelper::uriColumnSorter('Col Label', 'model.value_wanted') }}</th>
                <th>Another Col</th>
                <th>Last Col</th>
...

看起来很简单,它不工作的例子有一个相同布局的表,我以同样的方式调用辅助方法,只是交换了数据名称。

该函数调用,并且表头中的排序链接在那里并且是可点击的。它只是不会改变排序。

是什么阻止了它的工作?我是否需要指示该列在模型中的某处是可排序的?或者也许 docker 需要强制更新?不会这样认为,因为该方法执行但我不确定,docker 对我来说是新的。

先感谢您!

标签: phpmysqllaravelsortinghelper

解决方案


推荐阅读