Javascript 有没有办法用php检查url中的特定参数?
我正在使用一个名为chatter的包,并设法将其包含在我自己的帖子中。 现在我有了一个名为games的表格,每次我创建一个新游戏时,我都会添加一个聊天讨论。这很有效 因此,在单个游戏页面上,我将游戏的细节和聊天讨论作为iframe加载。这意味着现在我在HTML中有了一个HTML。 用户现在可以使用聊天讨论 控制器看起来很像这样:Javascript 有没有办法用php检查url中的特定参数?,javascript,php,jquery,laravel,Javascript,Php,Jquery,Laravel,我正在使用一个名为chatter的包,并设法将其包含在我自己的帖子中。 现在我有了一个名为games的表格,每次我创建一个新游戏时,我都会添加一个聊天讨论。这很有效 因此,在单个游戏页面上,我将游戏的细节和聊天讨论作为iframe加载。这意味着现在我在HTML中有了一个HTML。 用户现在可以使用聊天讨论 控制器看起来很像这样: public function show(Game $game) { // We know this is a game // Get the cate
public function show(Game $game)
{
// We know this is a game
// Get the category first
$category = DB::table('chatter_categories')->whereName('Game')->first();
// Get the discussion
// A discussion has many post(s)
$discussion = DB::table('chatter_discussion')->whereChatterCategoryId($category->id)->first();
//dd($chatter_post);
return view('games.games', ['game' => $game, 'discussion' => $discussion, 'category' => $category]);
}
Route::resource('games', 'GameController');
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$parsedURL = parse_url($actual_link);
parse_str($parsedURL['forums'], $parts);
echo $query['forums'];
现在,在我的games.blade中,我有以下几点:
<article id="discussion">
<iframe id="myiframe" src="/forums/discussion/{{ $category->slug }}/{{ $discussion->slug }}" style="height: 800px; width: 100%;" frameborder="0" />
</article>
它将删除标题,但如果我访问chatter原始前端视图,这也将消失
这时我想到了检查当前页面的URL和相应的样式,但这不起作用
我的比赛路线如下所示:
public function show(Game $game)
{
// We know this is a game
// Get the category first
$category = DB::table('chatter_categories')->whereName('Game')->first();
// Get the discussion
// A discussion has many post(s)
$discussion = DB::table('chatter_discussion')->whereChatterCategoryId($category->id)->first();
//dd($chatter_post);
return view('games.games', ['game' => $game, 'discussion' => $discussion, 'category' => $category]);
}
Route::resource('games', 'GameController');
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$parsedURL = parse_url($actual_link);
parse_str($parsedURL['forums'], $parts);
echo $query['forums'];
如果使用Laravel,则可以使用URL查询参数执行此操作:
if ($request->has('forums')) {
// do stuff here
}
看
在模板中,您可以使用:
@if(app('request')->input('forums'))
<span>Do stuff</span>
@endif
@if(应用程序('request')->输入('forums'))
做事
@恩迪夫
请参阅:如果使用Laravel,可以使用URL查询参数执行此操作:
if ($request->has('forums')) {
// do stuff here
}
看
在模板中,您可以使用:
@if(app('request')->input('forums'))
<span>Do stuff</span>
@endif
@if(应用程序('request')->输入('forums'))
做事
@恩迪夫
请参阅:尝试以下方法:
public function show(Game $game)
{
// We know this is a game
// Get the category first
$category = DB::table('chatter_categories')->whereName('Game')->first();
// Get the discussion
// A discussion has many post(s)
$discussion = DB::table('chatter_discussion')->whereChatterCategoryId($category->id)->first();
//dd($chatter_post);
return view('games.games', ['game' => $game, 'discussion' => $discussion, 'category' => $category]);
}
Route::resource('games', 'GameController');
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$parsedURL = parse_url($actual_link);
parse_str($parsedURL['forums'], $parts);
echo $query['forums'];
试着这样做:
public function show(Game $game)
{
// We know this is a game
// Get the category first
$category = DB::table('chatter_categories')->whereName('Game')->first();
// Get the discussion
// A discussion has many post(s)
$discussion = DB::table('chatter_discussion')->whereChatterCategoryId($category->id)->first();
//dd($chatter_post);
return view('games.games', ['game' => $game, 'discussion' => $discussion, 'category' => $category]);
}
Route::resource('games', 'GameController');
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$parsedURL = parse_url($actual_link);
parse_str($parsedURL['forums'], $parts);
echo $query['forums'];
你可以试试-
$parse = parse_url('http://domain.local/forums/discussion/game/sidney-game', PHP_URL_PATH);
if (strpos($parse, '/forums/') === 0) {
// do what needed
}
它将检查路径是否以论坛开始
您可以尝试-
$parse = parse_url('http://domain.local/forums/discussion/game/sidney-game', PHP_URL_PATH);
if (strpos($parse, '/forums/') === 0) {
// do what needed
}
它将检查路径是否以
论坛开始
您的路由定义是什么?路由定义会更有用。请尝试此{{Request::segment(1)}}//1是URL参数位置。您可以更改此2或其他内容。您的问题似乎是错误的,因为您要求的是参数,但实际上您指的是路径段(根据您提供的url判断)。您的路由定义是什么?路由定义会更有用。请尝试此{{Request::segment(1)}}//1是url参数位置。你可以修改这个2或者其他什么。你的问题看起来是错的,因为你要求的是一个参数,但实际上你指的是一个路径段(根据你提供的url判断)。我认为您在更新答案时缺少了parse\u url
中的第2个参数。我认为您在更新答案时缺少了parse\u url
中的第2个参数。这将检查查询字符串参数是否有论坛
@sougatabase,如果您是对的。我假设问题涉及查询字符串参数。这将检查查询字符串参数是否有论坛
@sougatabase您是对的。我假设问题涉及查询字符串参数。