【发布时间】:2015-06-26 00:42:23
【问题描述】:
因此,我目前正在处理一个项目,其中有一个表格,其中显示了经理的概述以及他们分配给当前具有特定状态的应用程序的数量。我要做的是当用户单击一个数字(即计数)时,它会返回一个列表视图,该视图仅从数据库中查询分配给该经理和该状态的那些应用程序。否则,如果用户转到应用程序视图,它应该显示所有应用程序。
这是我的概览视图的代码:
<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 链接来路由或类似的东西吗?我还不确定。任何提示将不胜感激!
【问题讨论】:
标签: php mysql laravel model-view-controller