HREF将参数发送到控制器并返回View

时间:2015-06-25 16:35:06

标签: php mysql laravel model-view-controller

所以我目前正在开发一个项目,其中我有一个表格,其中显示了管理人员的概述以及他们分配给当前具有特定状态的应用程序的数量。我要做的是当用户点击一个数字(这是一个计数)时,它返回一个列表视图,该视图仅从数据库查询分配给该管理器的那些应用程序和该状态。否则,如果用户转到应用程序视图,它应该显示所有应用程序。

以下是我的概述视图的代码:

    <table class="table tablesorter" id="tblAffs">
  <thead>
  <tr class="tblhead">
    <th>AM</th>
    <th>Qualified Prospect</th>
    <th>Unqualified Prospect</th>
    <th>Contacted</th>
    <th>Converted To Account</th>
    <th>Pending Integration</th>
    <th>Revenue Generating</th>
  </tr>
  </thead>
  <tbody>

  @foreach ($totalCount as $id => $name) {{-- id is the admin id --}}
    @foreach($name as $n => $status)  {{-- $n is the name, $status is array of the counts --}}
    <tr>
      <td>
        {{$n}}
        <br>
        <a href="#">Closed</a>
      </td>
          <td><a href="/ap1/{{$new_lead}}/applications?status=2">{{ isset($status[2]) ? $status[2] : 0 }}</a></td>
          <td><a href="/ap1/{{$new_lead}}/applications?status=1">{{ isset($status[1]) ? $status[1] : 0 }}</a></td>
          <td><a href="/ap1/{{$new_lead}}/applications?status=3">{{ isset($status[3]) ? $status[3] : 0 }}</a></td>
          <td><a href="/ap1/{{$new_lead}}/applications?status=4">{{ isset($status[4]) ? $status[4] : 0 }}</a></td>
          <td><a href="/ap1/{{$new_lead}}/applications?status=5">{{ isset($status[5]) ? $status[5] : 0 }}</a></td>
          <td><a href="/ap1/{{$new_lead}}/applications?status=6">{{ isset($status[6]) ? $status[6] : 0 }}</a></td>
    </tr>
  @endforeach
  @endforeach



  </tbody>
</table>

在本概述的控制器上,这是代码以及如何创建数据结构:

     public function overview()
  {
    $query= DB::table('admins')
      ->join('advertiser_applications', 'admins.id', '=', 'advertiser_applications.assigned_to')
      ->selectRaw('advertiser_applications.status, admins.id, admins.first_name, COUNT(advertiser_applications.status) count')
      ->groupBy('admins.id', 'advertiser_applications.status');

    $counts = $query->get();
    $totalCount = [];
    foreach($counts as $count){
      $totalCount[$count->id][$count->first_name][$count->status] = $count->count;
    }
    return View::make('admin.crm.overview', ['totalCount' => $totalCount, 'admin_id' => AuthAdmin::admin(false), 'tpl_title' => 'CRM Advertiser Overview', 'new_lead' => 'advertisers']);

  }

以下是我的控制器中用于显示列表的代码。这就是我对如何传递该状态以及如果点击该href的id感到困惑的地方。

   public function index($param)
  {
    $query = AdvertiserApplication::with('admin');
    $status = Input::get('status');

    if (!empty($status) || $status === '0')
      $query->where('status', '=', $status);

    $applications = $query->get();

    return View::make('admin.advertisers.application_list', ['applications' => $applications, 'admin_id' => AuthAdmin::admin(false)]);
  }

现在我不确定这是否是我在href中编写的链接的正确方法。我应该做一个URL链接路由或类似的东西吗?我还不确定。任何提示将不胜感激!

1 个答案:

答案 0 :(得分:1)

使用此URL:

 <a href="/ap1/{{$new_lead}}/applications?status=2">{{ isset($status[2]) ? $status[2] : 0 }}</a>

如果你有

route::get('/ap1/{new_lead}', array('as' => 'page-name', 'uses' => 'yourController@functionName'));
控制器中的

public function functionName($new_lead){
 // use $new_lead here to get your data
}