我通过“incude”语句在“index.php”上调用我的页面。我不得不使用“isset”来让它们工作,但是当我单击导航栏中的链接时,“yourtweets.php”没有加载。我是否正确使用它?
链接代码;
<a href="?page=yourtweets" class="nav-link">Your Tweets</a>
index.php代码;
<?php
include("functions.php");
include("views/header.php");
if (isset($_GET['page']) == 'timeline') {
include("views/timeline.php");
} else if (isset($_GET['page']) == 'yourtweets') {
include("views/yourtweets.php");
} else {
include("views/home.php");
}
?>
最佳答案
来自PHP Manual :
Returns TRUE if var exists and has value other than NULL. FALSE otherwise.
您正在检查 bool 值 (TRUE/FALSE) 是否等于您的页面名称。将其替换为以下内容,它应该可以工作:
if (isset($_GET['page']) && $_GET['page'] == 'timeline') { //if page is set and page = timeline
include("views/timeline.php");
} else if (isset($_GET['page']) && $_GET['page'] == 'yourtweets') {
include("views/yourtweets.php");
} else {
include("views/home.php");
}
希望对您有所帮助!
编辑:对不起@EatPeanutButter,我发布答案后才看到你的评论!
关于php - Isset 获取页面与 php 的正确用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47579258/