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

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

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

問題描述

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

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.

型號:

    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 模式中控制器的目的是改變模型層的狀態.

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

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

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.

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

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
    
}

控制者負責什么?

MVC 架構模式中的控制器負責:

  • 初始化部分模型層
  • 從模型層檢索數據
  • 輸入驗證
  • 初始化視圖
  • 選擇模板
  • 創建響應
  • 訪問控制
  • ...等

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

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

相關文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
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 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 毛片网站免费观看 | 成人观看视频 | 日韩免费小视频 | 日本欧美在线 | 国产美女av| 在线观看的av网站 | 亚洲天堂一区 | 深夜免费福利 | 四虎入口 | 免费av在线 | 三级福利视频 | 国产成人免费在线视频 | 成人羞羞国产免费游戏 | 成人免费视屏 | 福利在线播放 | 香港三日本三级少妇66 | 国产成人久久精品麻豆二区 | 手机在线播放av | 国产天天操 | 成人精品三级av在线看 | 国产一级免费视频 | 大尺度做爰呻吟舌吻网站 | 日韩a在线观看 | 欧美另类综合 | 日韩视频网 | 日日操夜夜骑 | www操 | 欧美精品成人 | 久久一级片 | 午夜私人影院 | 亚洲人在线观看 | 丁香六月激情 | 欧美做受喷浆在线观看 | 四虎影院最新地址 | 黄色成人免费网站 | 一区二区三区四区在线视频 | 午夜理伦三级理论 | 亚洲综合成人网 | 日韩免费精品视频 | 日韩中文字幕 | 四虎影 |