如何通过“智能”URL正确处理表单


How to correctly handle forms through "smart" URL

我目前正在做一个私人项目,以帮助我掌握聪明的窍门并使用SEO友好的URL。

我开发了一些类似于 MVC 类型应用程序的东西,其中所有内容都通过网站示例的索引进行路由:

/*
    Display The Page which is located in the first element of the new array 
*/
$Views->Display_Page($Parameters[0]);

在上面的示例中,我当前的 URL 结构为:

127.0.0.1/SPT/注册

细分:

127.0.0.1 = 网址

SPT = 子目录

注册 = 要显示的页面。

页面的显示方式

我在$Views变量中使用了基于方法的结构,其运行方式如下:

public function Display_Page($PageName){
    /*
        This is the main call from the index page:
            Index.php -> $Parameters[0] will server as the page name.
        This function will check if there is a method which will act as the outer core for the Framework.
            If Method is detected, then display the page by appending .tpl to the end of the variable passed
            if Method is not detected, then display a 404 page
    */
        if (!method_exists($this,$PageName)){
            $this->_Instance->assign("css",$this->DirectoryStructure()."/Templates/Fluid_New/CSS/css404.css");
            $this->_Instance->display("404.html");
            exit;
        }
        call_user_func(array($this, $PageName),$PageName);
        $this->_Instance->display($PageName.".tpl");
    }
}

因此,如果创建了 $views 中的方法,则会显示页面,否则显示 404 页面。

现在,在这个结构中,我面临着处理多个表单的问题,这些表单都发布到索引页面。

我将如何根据$_POST的内容处理不同的表格?

我不知道

我是否完全理解您的问题,但我在一个页面上处理带有隐藏字段的多个表单。

// form 1
<form action="" method="POST">
    <input type="hidden" name="form" value="form1">
    ...
</form>
// form 2
<form action="" method="POST">
    <input type="hidden" name="form" value="form2">
    ...
</form>
// validation/saving
if ($_POST['form'] == 'form1') {
    // do the form validation and saving stuff
}
else if ($_POST['form'] == 'form2') {
    // do the form validation and saving stuff
}