通过 get 方法在开关上未定义的变量
Undefined variable on switch via get method
我有一个带有选项注释的 cms 管理部分;当我在管理菜单上按评论时,它应该带我到 comments.php,其中包括下面的代码;默认情况下,它应该将我所有的评论加载到一个网格上,但是当我按评论时它不显示任何页面是空白的?我的代码:
<?php
if(isset($_GET['source'])){
$source1=$_GET['source'];
if(!empty($source1)){
switch($source1){
case 'add_post':
include"includes/add_posts.php";
break;
case 'edit_post':
include"includes/edit_post.php";
break;
case 'view_all_comments':
include "includes/view_all_comments.php";
break;
default:
include "includes/view_all_comments.php";
}
}
}
?>
当你加载 comments.php 时 url 没有通过 get 发送任何参数,在你的代码上你正在检查源是否不为空,在你的情况下它首先是空的。然后预制开关声明,在你的情况下它不会预制开关,因为源是空的,这就是你什么都看不到的原因。您可以通过在 if 上添加 else 并包含 view_all_comments.php 或喜欢下面的代码来解决此问题:
<?php
$source1=isset($_GET['source']);
switch($source1){
case 'add_post':
include"includes/add_posts.php";
break;
case 'edit_post':
include"includes/edit_post.php";
break;
case 'view_all_comments':
include "includes/view_all_comments.php";
break;
default:
include "includes/view_all_comments.php";
}
?>
我有一个带有选项注释的 cms 管理部分;当我在管理菜单上按评论时,它应该带我到 comments.php,其中包括下面的代码;默认情况下,它应该将我所有的评论加载到一个网格上,但是当我按评论时它不显示任何页面是空白的?我的代码:
<?php
if(isset($_GET['source'])){
$source1=$_GET['source'];
if(!empty($source1)){
switch($source1){
case 'add_post':
include"includes/add_posts.php";
break;
case 'edit_post':
include"includes/edit_post.php";
break;
case 'view_all_comments':
include "includes/view_all_comments.php";
break;
default:
include "includes/view_all_comments.php";
}
}
}
?>
当你加载 comments.php 时 url 没有通过 get 发送任何参数,在你的代码上你正在检查源是否不为空,在你的情况下它首先是空的。然后预制开关声明,在你的情况下它不会预制开关,因为源是空的,这就是你什么都看不到的原因。您可以通过在 if 上添加 else 并包含 view_all_comments.php 或喜欢下面的代码来解决此问题:
<?php
$source1=isset($_GET['source']);
switch($source1){
case 'add_post':
include"includes/add_posts.php";
break;
case 'edit_post':
include"includes/edit_post.php";
break;
case 'view_all_comments':
include "includes/view_all_comments.php";
break;
default:
include "includes/view_all_comments.php";
}
?>