Viewperを持つことの利点は何Controllerですか?私が読んだものは、 perViewsを持つべき理由を明確に示したり実証したりしていません。ViewController
現時点では、次のようなものがあります(主な方法だけに短縮されています):
interface ViewInterface {
public function render();
}
class View implements ViewInterface {
private $template;
public function __construct($template = NULL) {
if($template !== NULL) {
$this->setTemplate($template);
}
}
public function render() {
ob_start();
require(PATH_TEMPLATES . $this->template . '.php');
return ob_get_clean();
}
}
class CompositeView implements ViewInterface {
private $views;
public function attachView(ViewInterface $view) {
$this->views[] = $view;
return $this;
}
public function render() {
$output = '';
foreach($this->views as $view) {
$output .= $view->render();
}
return $output;
}
}
プライバシー ポリシー ページをレンダリングしたいとしましょう。次のように実行できます。
$header = new View('common/header');
$body = new View('privacy-policy');
$footer = new View('common/footer');
$compositeView = new CompositeView();
$compositeView->attachView($header)
->attachView($body)
->attachView($footer);
$compositeView->render();
これの何が問題なのですか?Viewそれぞれの を別々にすることで、どのような利点がありますControllerか?
どんなアドバイスでも大歓迎です。