【问题标题】:How to get data from a form in php mvc如何从 php mvc 中的表单中获取数据
【发布时间】:2011-11-22 05:06:04
【问题描述】:

我开始学习 php 和 mvc,这就是我想做的。我想创建一个简单的登录表单。 我的登录表单如下

<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);
}

登录视图加载,但如何使用登录功能将表单中的数据获取到模型?

编辑:

我的 index.php

define ('SERVER_ROOT','C:\wamp\www\eclipse\MVCLMS');

define ('SITE_ROOT', 'http://localhost');

require_once 'controller/router.php';

?>

我的 router.php 文件

<?php
include 'model/modelBook.php';
include 'model/modelLogin.php';
include 'view/load.php';
include 'controller/controller.php';

$controller = new controller();
?>

【问题讨论】:

    标签: php forms model-view-controller


    【解决方案1】:

    你的 index.php 中应该有以下函数

    <?php
       if ($_POST['username'] && $_POST['password'] ) {
          $controller = new controller();
          $controller->login($_POST['username'], $_POST['password']);
       }
    ?>
    

    此代码位置取决于您的 mvc 结构。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 2021-03-11
      相关资源
      最近更新 更多