久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

MVC模式中使用PHP的控制器的目的是什么?

What is the purpose of the controller in the MVC pattern using PHP?(MVC模式中使用PHP的控制器的目的是什么?)
本文介紹了MVC模式中使用PHP的控制器的目的是什么?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我剛剛進(jìn)入 MVC 設(shè)計(jì)模式.這里的一個(gè)簡單示例并沒有明確我對控制器使用的概念.能否請您解釋一下控制器的實(shí)際使用,同時(shí)保持簡單.

I am just heading into MVC design pattern. A simple example here does not clear my concept about the use of controller. Could you please explain real use of controller while keeping it simple.

型號(hào):

    class Model {
       public $text;

       public function __construct() {
           $this->text = 'Hello world!';
       }        
    }

控制器:

      class Controller {
          private $model;

          public function __construct(Model $model) {
              $this->model = $model;
          }
      }

查看:

      class View {
         private $model;
         //private $controller;

         public function __construct(/*Controller $controller,*/ Model $model) {
             //$this->controller = $controller;
             $this->model = $model;
         }

          public function output() {
               return '<h1>' . $this->model->text .'</h1>';
         }

      }

索引:

      require_once('Model.php'); 
      require_once('Controller.php');
      require_once('View.php');

      //initiate the triad
      $model = new Model();
      //It is important that the controller and the view share the model
      //$controller = new Controller($model);
      $view = new View(/*$controller,*/ $model);
      echo $view->output();

推薦答案

MVC 模式中控制器的目的是改變模型層的狀態(tài).

Controllers purpose in MVC pattern is to alter the state of model layer.

它是通過控制器接收用戶輸入來完成的(優(yōu)選 - 抽象為諸如 Request 實(shí)例之類的東西),然后根據(jù)從用戶輸入中提取的參數(shù),傳遞模型層適當(dāng)部分的值.

It's done by controller receiving user input (preferable - abstracted as some thing like Request instance) and then, based on parameters that are extracted from the user input, passes the values to appropriate parts of model layer.

與模型層的通信通常通過各種服務(wù)發(fā)生.反過來,這些服務(wù)負(fù)責(zé)管理持久性抽象和域/業(yè)務(wù)對象之間的交互,也稱為應(yīng)用程序邏輯".

The communication with model layer usually happens via various services. These services in turn are responsible for governing the interaction between persistence abstraction and domain/business objects, or also called "application logic".

class Account extends ComponentsController
{

    private $recognition;

    public function __construct(ModelServicesRecognition $recognition)
    {
        $this->recognition = $recognition;
    }

    public function postLogin($request)
    {    
        $this->recognition->authenticate(
            $request->getParameter('credentials'),
            $request->getParameter('method')
        );
    }

    // other methods
    
}

控制者負(fù)責(zé)什么?

MVC 架構(gòu)模式中的控制器負(fù)責(zé):

  • 初始化部分模型層
  • 從模型層檢索數(shù)據(jù)
  • 輸入驗(yàn)證
  • 初始化視圖
  • 選擇模板
  • 創(chuàng)建響應(yīng)
  • 訪問控制
  • ...等

這篇關(guān)于MVC模式中使用PHP的控制器的目的是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動(dòng)作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發(fā)技術(shù)
Having a single entry point to a website. Bad? Good? Non-issue?(有一個(gè)網(wǎng)站的單一入口點(diǎn).壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務(wù)層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 日本精品视频在线观看 | 亚洲免费在线视频 | 亚洲精品福利视频 | 在线免费观看成年人视频 | 亚洲精品电影网在线观看 | 欧美色性 | 免费视频久久 | 二区视频 | 五月婷婷丁香婷婷 | 国产福利91精品一区二区三区 | 婷婷久久综合 | 一区二区三区视频在线观看 | 久久久夜色精品亚洲 | 国产一级毛片精品完整视频版 | 91传媒在线播放 | 久久久久久久亚洲精品 | 日本欧美在线 | 日本精品久久久久久久 | 狠狠操狠狠色 | 久久成人一区 | 美女久久久久久久 | 精品成人佐山爱一区二区 | avav在线看 | 91久久精品日日躁夜夜躁欧美 | 色综合视频 | 日韩淫片免费看 | 久久久一区二区三区四区 | 色偷偷噜噜噜亚洲男人 | 成人h免费观看视频 | 91精品国产欧美一区二区 | 国产精品入口 | 欧美综合国产精品久久丁香 | 久久综合久色欧美综合狠狠 | 欧美在线视频观看 | 美女激情av | 亚洲综合大片69999 | 亚洲一区二区三区四区五区午夜 | 不卡视频一区二区三区 | 久久精品在线 | 国产精品久久一区二区三区 | 久久99精品久久久久久 |