繁体   English   中英

有没有办法用php检查网址中的特定参数?

[英]Is there a way to check for a specific parameter in a url with php?

我正在使用一个名为chatter的程序包,并设法将其包含在我自己的帖子中。 现在,我有了一个称为游戏的表,每次创建新游戏时,我还会添加一个讨论讨论。 这样可行。

因此,在单个游戏页面上,我将游戏的详细信息和聊天讨论作为iframe加载。 这意味着我现在在HTML中有一个HTML。 用户现在可以使用聊天讨论。

控制器看起来非常像这样:

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]);
}

现在,在我的games.blade中,我有以下内容:

<article id="discussion">
    <iframe id="myiframe" src="/forums/discussion/{{ $category->slug }}/{{ $discussion->slug }}" style="height: 800px; width: 100%;" frameborder="0" />
</article>

Chatter的默认页面带有标题,如下图所示:

在此处输入图片说明

如果我查看自己创建的游戏,那么也会看到与该游戏有关的聊天讨论:

在此处输入图片说明

问题:如何仅在游戏页面上删除聊天讨论的标题部分?

如果我只是直接定位标头ID

div#chatter_header{ 
    display: none;
}

它将删除标题,但是如果我访问颤振原始前端视图,该标题也将消失。

这是我想到检查当前页面URL和相应样式的时候,但这不起作用。

我的游戏路线如下:

Route::resource('games', 'GameController');

如果您使用Laravel,则可以使用URL查询参数执行此操作:

if ($request->has('forums')) {
    // do stuff here
}

参见https://laravel.com/docs/5.7/requests#retrieving-input

在模板中,您可以使用:

@if(app('request')->input('forums'))
   <span>Do stuff</span>
@endif 

请参阅: 流明:在“刀片”视图中获取URL参数

你可以试试 -

$parse = parse_url('http://domain.local/forums/discussion/game/sidney-game', PHP_URL_PATH);

if (strpos($parse, '/forums/') === 0) {
  // do what needed
}

它将检查路径是否以forums开头。

尝试这样的事情:

$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'];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM