如何在php mvc中从表单获取数据
我开始学习php和mvc,这就是我想要做的。我想创建一个简单的登录表单。 我的登入表格如下如何在php mvc中从表单获取数据,php,forms,model-view-controller,Php,Forms,Model View Controller,我开始学习php和mvc,这就是我想要做的。我想创建一个简单的登录表单。 我的登入表格如下 <html> <body> <form action = "index.php" method = "post"> userName : <input type = "text" name = "username"/> Password : <input type = "text" name = "password"/> <br/>
<html>
<body>
<form action = "index.php" method = "post">
userName : <input type = "text" name = "username"/>
Password : <input type = "text" name = "password"/>
<br/>
<input type = "submit" value = "login" name = "btnlogin"/>
</form>
</body>
</html>
<?php
class controller
{
public $modelBook;
public $view;
public $modeluser;
function __construct()
{
$this->modelBook = new Book();
$this->view = new view();
$this->modeluser = new members();
$this->Home();
}
function Home()
{
$this->view->viewThis('login.php');
}
function login($username,$password)
{
$data = $this->modeluser->login($username, $password);
$this->view->viewThis('member.php',$data);
}
my router.php文件
<?php
include 'model/modelBook.php';
include 'model/modelLogin.php';
include 'view/load.php';
include 'controller/controller.php';
$controller = new controller();
?>
在index.php中应该有以下函数
define ('SERVER_ROOT','C:\wamp\www\eclipse\MVCLMS');
define ('SITE_ROOT', 'http://localhost');
require_once 'controller/router.php';
?>
<?php
if ($_POST['username'] && $_POST['password'] ) {
$controller = new controller();
$controller->login($_POST['username'], $_POST['password']);
}
?>
此代码位置取决于您的mvc结构