【发布时间】:2017-05-02 15:39:09
【问题描述】:
我在将多个变量从控制器传递到视图/刀片时遇到问题。我使用compact() 来传递变量,但我认为我已经达到了传递变量的极限,因为我已经测试了我的代码,它会在传递 30 个变量 后停止工作。并且会给出一个错误:“未定义的变量:”尽管它已经定义并且运行完美,除非我传递超过 30 个变量。我需要传递许多变量,因为我正在创建一个图表,图表中的每个值(x,y 轴)都是一个不同的变量。有没有其他方法可以做到这一点?我正在考虑为单个视图使用多个控制器。可能吗?
无论如何,这是我的控制器的一个 sn-p:
$ic15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 0)->where('year_admitted', 2015)->count();
$cas15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 1)->where('year_admitted', 2015)->count();
$ce15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 2)->where('year_admitted', 2015)->count();
$uep15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 3)->where('year_admitted', 2015)->count();
$ced15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 4)->where('year_admitted', 2015)->count();
$cet15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 5)->where('year_admitted', 2015)->count();
$saec15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 6)->where('year_admitted', 2015)->count();
$cgb15 = SchoolStats::where('school_id', $id)->groupBy('college_id')->where('college_id', 7)->where('year_admitted', 2015)->count();
return view('success', compact('col','school', 'total', 'f', 'm', 'ic', 'cas', 'ce', 'uep', 'ced', 'cet', 'saec', 'cgb', 'icf', 'icm', 'casf', 'casm', 'cef', 'cem', 'uepf', 'uepm', 'cedf', 'cedm', 'cetf', 'cetm', 'saecf', 'saecm', 'cgbf', 'cgbm', 'ic13', 'cas13', 'ce13', 'uep13', 'ced13', 'cet13', 'saec13', 'cgb13', 'ic14', 'cas14', 'ce14', 'uep14', 'ced14', 'cet14', 'saec14', 'cgb14', 'ic15', 'cas15', 'ce15', 'uep15', 'ced15', 'cet15', 'saec15', 'cgb15'));
这只是一个sn-p,其他变量已经在$ic15之前定义了。它的定义和使用就像上面显示的从 $ic15 到 $cgb15 的其他变量一样。
【问题讨论】:
标签: php laravel blade laravel-5.4