[英]PHP undefined variable $page_id - Includes
I have the following code: this is index.php initialize.php init the database connection我有以下代码:这是 index.php 初始化。php 初始化数据库连接
<?php require_once('../private/initialize.php'); ?>
<?php
if(isset($_GET['id'])){
$page_id = $_GET['id'];
$page = find_page_by_id($page_id);
if(!$page){
redirect_to(url_for('/index.php'));
}
}
?>
<?php include(SHARED_PATH.'/public_header.php'); ?>
<div id="main">
<?php include(SHARED_PATH.'/public_navigation.php'); ?>
<div id="page">
<?php
if(isset($page)){
echo $page['content'];
} else {
include(SHARED_PATH.'/static_homepage.php');
}
?>
</div>
</div>
<?php include(SHARED_PATH.'/public_footer.php'); ?>
here is the public_navigation.php bellow:这是 public_navigation.php 波纹管:
<navigation>
<?php
echo $page_id;
exit;
?>
<?php $nav_subjects = find_all_subjects(); ?>
<ul class="subject">
<?php while($nav_subject = mysqli_fetch_assoc($nav_subjects)) { ?>
<li>
<a href="<?php echo url_for('/index.php'); ?>">
<?php echo h($nav_subject['menu_name']); ?>
</a>
<?php $nav_pages = find_pages_by_subject_id($nav_subject['id']); ?>
<ul class="pages">
<?php while($nav_page = mysqli_fetch_assoc($nav_pages)) { ?>
<li class="<?php if($nav_page['id'] == $page_id){ echo 'selected'; } ?>">
<a href="<?php echo url_for('/index.php?id='.h(u($nav_page['id']))); ?>">
<?php echo h($nav_page['menu_name']); ?>
</a>
</li>
<?php } ?>
</ul>
<?php mysqli_free_result($nav_pages); ?>
</li>
<?php } ?>
</ul>
<?php mysqli_free_result($nav_subjects); ?>
</navigation>
I am not able to get $page_id from index.php -> Undefined variable in public_navigation.php!我无法从 index.php -> public_navigation.php 中的未定义变量中获取 $page_id!
When calling index.html, echo $page_id;调用 index.html 时, echo $page_id; returns back undefined..
返回未定义..
This is I want to set in public_navigation.php这是我想在 public_navigation.php 中设置
<li class="<?php if($nav_page['id'] == $page_id){ echo 'selected'; } ?>">
when calling index.html, $page_is is not set in navigation, and navigation runs..调用 index.html 时,导航中未设置 $page_is,导航运行..
if(!isset($page_id)) { $page_id = 1; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.