English 中文(简体)
PHP MVC
原标题:PHP MVC question
  • 时间:2010-08-11 03:48:08
  •  标签:
  • php

鉴于<代码> 冷藏/代码>类别和<代码>View类别,控制者直接分配价值来看待财产,还是更好地将价值分配给控制器内的财产,然后在准备展示这些财产时将其复制到观点?

www.un.org/Depts/DGACM/index_spanish.htm 例类:

class Model
{
  public $propertyA;
  public $propertyB;
}

www.un.org/Depts/DGACM/index_spanish.htm 例:

class Controller
{
  protected $view;
  protected $model;

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

    $this->view = new View();
    $this->prepareData();
    $this->initView();
  }

  protected function prepareData()
  {
    $this->model->propertyA =  This is property A. ;
    $this->model->propertyB =  This is property B. ;        
  }

  protected function initView()
  {
    $this->view->model = $this->model;
    $this->view->display();
  }
}

www.un.org/Depts/DGACM/index_spanish.htm 例 观点类别:

class View
{
  public $model;

  public function display()
  {
    echo "propertyA = $this->model->propertyA";
    echo "propertyB = $this->model->propertyB";
  }
}    

www.un.org/Depts/DGACM/index_spanish.htm 休业。 我确实使用一种模式,因此请重新考虑你对此的答复。

最佳回答

数据只能放在一个地方。 如果事情变得复杂,那么很难把你掌握的数据的不同地点混为一谈。 在多指标类集调查中,你有一个模式,即数据应当在哪里。 通过《示范法》,并表明这种观点。

http://en.wikipedia.org/wiki/Model%E2% http://ootips.org/mvc-pattern.html

该模型可以简单地作为具有该特性的类别。

问题回答

除非与列报方式有关,否则意见不应设定变量。 最好把静态变数放在一个汇点上。

将这些财产抄录给考虑

不要把变数定在一种观点中,为什么不要求你在提及控制者时提出看法。 这应当避免你撰写大量锅炉板。

Class Controller() {
  $this->something =  abc ;
  function __construct() {
    $this->display();
  }
  function display() {
    $this->view = new View($this);
  }
}

Class View() {

  function View(&$controller) {
    $this->controller = $controller;
    print $this->controller->something;
  }

}

<><>Edit>: 我和罗姆人一样,回答的比我自己大得多。 您应将这一模式纳入考虑。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签