关于简单的PHP MVC示例

关于简单的PHP MVC示例,php,model-view-controller,Php,Model View Controller,在PHP中存在一个简单的MVC示例。问题是,这个例子在 $action = $_GET['action']; if(function_exists($action) && !substr($action,0,1)=="_"){ $action(); }else{ echo "<h1>404 Page Not Found</h1><p>The page you requested could not be found</p&

在PHP中存在一个简单的MVC示例。问题是,这个例子在

$action = $_GET['action'];
if(function_exists($action) && !substr($action,0,1)=="_"){
    $action();
}else{
    echo "<h1>404 Page Not Found</h1><p>The page you requested could not be found</p>";
}
$action=$\u GET['action'];
如果(函数_存在($action)和&!substr($action,0,1)=“u”){
$action();
}否则{
echo“404页面未找到无法找到您请求的页面”

; }
改为:

    $action = $_GET['action'];
if(function_exists($action) || !substr($action,0,1)=="_"){
    $action();
}else{
    echo "<h1>404 Page Not Found</h1><p>The page you requested could not be found</p>";
}
$action=$\u GET['action'];
如果(函数_存在($action)| |!substr($action,0,1)==“|”){
$action();
}否则{
echo“404页面未找到无法找到您请求的页面”

; }
和&更改为|。或者完全!substr($action,0,1)=“删除”。什么是不允许此行运行$action

=======================


编辑:问题是路由器不能与&&一起工作

这是因为
&

这么说来

if(function_exists($action) && !substr($action,0,1)=="_"){
如果函数存在
,则
substr
不包含uu2; than run

这意味着

|
,所以这意味着

if(function_exists($action) || !substr($action,0,1)=="_"){
如果函数存在,但字符串包含
它将失败, 或者,如果函数不存在,但字符串不包含
\uu
,它仍将失败

因此,
&&
检查两者是否都正常,无论其中一个是否有效,如果另一个失败或无效,它都会按照您上面指定的404

我希望它能帮助你,如果不清楚,我会尝试用另一种方式来描述它

发件人:

致:


你为什么要这样?通常是跟踪私有函数,这些函数只能在其他类函数中使用。为什么用“mvc”标记?问题应该是“substr()如何工作?”我想你不明白我的意思。我对语法没有问题,我的谈话是在路由器工作的时候。好啊
if(function_exists($action) && !substr($action,0,1)=="_")
if(function_exists($action) && !(substr($action,0,1)=="_"))