可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm still very new at Laravel.
I got problem how can I use Isset($_GET)
?
How to get for example: http://virtualhost.com/flytrap/public/location?city=25?
Usually when at pure PHP, I always use:
if (isset($_GET["submit"])) { $location = $_GET["city"]; }
to get city value. So I can use it for query at database. If I use Core PHP method I got an error.
回答1:
You can use below code
$location = Request::query('city', false); //insed of $_GET['city'];
回答2:
This is Laravel equivalent (see http://laravel.com/docs/4.2/requests):
if (Input::has('submit')) { $location = Input::get('city'); }
But as Lalit Sharma says, you should maybe always set $location even if you have not "submit" in GET:
$location = Input::get('city', null);
null is the default value so you can ommit it or use any other value:
$location = Input::get('city', 'Reykjavik');