输入错误返回空查询 [英] Input returns empty query in error

查看:49
本文介绍了输入错误返回空查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个电影网站,希望允许人们按类型进行搜索

I have a movies website that I want to allow people to search by genre

movies.com/people/action/genre

movies.com/people/action/genre

路线

Route::get('people/{genre}/genre', array('uses' => 'ActorController@genre', 'as' => 'people.genre'));

ActorController @ genre

The ActorController@genre

public function genre()
{

    $genre=Input::get('genre');
        $actors = $this->actor->allgenre($genre);
            return View::make('Actor.All')->withActors($actors);

}

这会吸引数据库中的所有演员

This grabs all the actors from the db

function allGenre($genre)
{

        return $this->actor->where('genre', 'like', '$genre')->orderBy('views', 'desc')->paginate(24);

}

这没有返回结果,应该返回结果,因为如果我走了

This is returning no results, when it should be returning results because if I go

function allGenre($genre)
{

        return $this->actor->where('genre', 'like', 'action')->orderBy('views', 'desc')->paginate(24);

}

显示结果

推荐答案

使用该路由时,$ genre变量将绑定到控制器:

When you use that routing, the $genre variable would be bound the the controller:

public function genre($genre)
{
  $actors = $this->actor->allgenre($genre);
  return View::make('Actor.All')->withActors($actors);
}

在您的上一个问题中,您使用了查询字符串,因此您需要输入:: get (键"),现在您更改了网址,并且不再使用资源控制器,因此必须返回常规"方式

While in your previous question you used query strings, so you needed Input::get('key'), now you changed the url, and you don't use resource controllers anymore, so you must go back to the "usual" way

这篇关于输入错误返回空查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆