在我的模板中,我调用了这样一个函数:
loadResults('asc');
function loadResults(order) {
return $.get('{{ url('_example_results', { 'order' : ''}) }}'+order, function (html) {
$('#results').html(html);
});
}我的控制器中的函数如下所示:
public function resultsAction($order, Request $request)
{
// content is not crucial for solving my problem
}我的结果没有加载,我得到了以下错误:
Controller "...resultsAction()" requires that you provide a value for the "$order" argument (because there is no default value or because there is a non optional argument after this one).我需要做什么调整?
发布于 2015-05-28 07:03:01
因为小枝在使用js之前呈现页面,所以您不能用小枝创建正确的路径。您可以使用两种方法对问题进行归档:
1)使param是可选的,并将其传递给查询字符串,如下所示:
js
loadResults('asc');
function loadResults(order) {
return $.get('{{ url('_example_results') }}'+"?order="order, function (html) {
$('#results').html(html);
});
}控制器
public function resultsAction(Request $request)
{
//...
$order= $request->get('order','asc'); // second parameter is the default if is null
}希望能帮上忙
https://stackoverflow.com/questions/30498472
复制相似问题