如何在php mysql中使用mvc框架创建表单?

Using mvc structure I create the files below it works, but I want to create a simple form and store that data into mysql database and retrieve data from db, where I will write query for db and config db. How to do this, please give me some idea guys...

THIS MY index.php file

     <?php 
     include_once('../../../mvc/Controller.php');


     if(!empty($_SERVER['QUERY_STRING'])){
       //reads and explodes the querystring into array eg 
       //index.php?Controller/getAllCars
      //where Controller end up in $querArray[0]=Controller 
    // and getAllCars end up in $queryArray[1]=getAllCars
       $queryArray=explode('/',$_SERVER['QUERY_STRING']);
       $controller=new $queryArray[0];
       //calls the method in the controller that gets data from the model
       //and assigns it to a view that presents it
       //$controller->getAllCars();

       if(isset($queryArray[2])){
          $controller->$queryArray[1]($queryArray[2]);
       }
       else{
         $controller->$queryArray[1]();
       }
     }
     echo '<a href="./index.php?Controller/getAllCars">Show cars</a>';
     ?> 

This my controller code:

    <?php
    include_once('../../../mvc/Model.php');
    include_once('../../../mvc/View.php');
    class Controller{
      private $model;
       private $view;
      function __construct(){
         $this->model=new Model();
          $this->view =new View();
      }
     public function getAllCars(){

        $cars=$this->model->getCars();


        //assigns data from the model to a variable cars
        //that will be presented in the "html" file
        $this->view->assign('cars',$cars);
        //displays the "html" file that will present data from the model
        $this->view->display('./cars.html');

      }
      public function getCarByRegnumber($regnumber){
         //assigns data from the model to a variable cars
        //that will be presented in the "html" file
        $this->view->assign('car', $this->model->getCarByRegnumber($regnumber));
        //displays the "html" file that will present data from the model
        $this->view->display('./cars.html');

      }
    }//end claSS  

    ?>

This my model.php code:

    <?php
    class Model {
      private $cars;
     function __construct(){
       $this->cars=array('abc123'=>'volvo','bbb123'=>'bmw','ccc123'=>'audi');//here values for variable assigned
     } 
     public function getCars(){
        return $this->cars;
      }
     public  function  getCarByRegnumber($regnumber){
       return $this->cars[$regnumber];

      }
    }
    ?>

this my view.php code:

    <?php
    class View {
     private $data=array();
      function assign($varname,$vardata){
         $this->data[$varname]=$vardata;
      }
      function display($filename){
        //extract the data that the controller got from the model
        extract($this->data);
        //include the file that presents the extracted data
        include($filename);
      }

    }


    ?>

this my cars.html code:

    <!doctype html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Your page title</title>
        <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.5.0/pure-min.css">
    </head>
    <body>
      <ul>
        <?php
        //loops the data that the controller got from the model and puttedd in th view
          foreach($cars as $key =>$car){
            echo '<li>';
            echo $car;
            echo '</li>';
          }

        ?>
        </ul>
    </body>
doulei1965
doulei1965 哦谢谢你......
接近 4 年之前 回复
dongxu4023
dongxu4023 那么,html表单显然属于视图所使用的视图或html模板(html还应该去哪里?)并且表单的处理由控制器初始化并由模型执行。
接近 4 年之前 回复
dongzhi4073
dongzhi4073 arkascha我有一个想法,但它不起作用所以我问你...请帮助我,我是一个初学者,所以我做这样的小任务来学习mvc..
接近 4 年之前 回复
douliang7068
douliang7068 对不起,不要弄错,但是......你可能不知道自己发布的代码是如何运作的吗?
接近 4 年之前 回复
duanqu9279
duanqu9279 请给我一个想法,我需要编写查询,我将在哪里创建简单的表单
接近 4 年之前 回复
douyimin1083
douyimin1083 我想知道在哪里需要编写查询来从db插入和检索数据
接近 4 年之前 回复
dpn68721
dpn68721 我会说如果你实现了你在这里发布的所有代码,那么你当然也会知道如何实现一个html表单。
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问