Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> MVC budowa widoku
morawcik89
post
Post #1





Grupa: Zarejestrowani
Postów: 56
Pomógł: 1
Dołączył: 15.07.2008

Ostrzeżenie: (0%)
-----


W jednym za artykułów przeczytałem o takim tworzeniu widoku:
Kod
class WebPage{
     private $pageController;
     private $controllerStyle;
     private $page='';
     public function __construct(PageController $pageController){
         $this->pageController=$pageController;
         $this->controllerStyle=$pageController->getStyle();
     }
     public function doHeader(){
         $this->page='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><link rel="stylesheet" href="defaultstyle.css" type="text/css" /><title>Sample Web Page</title></head>';
     }
     public function doBody(){
         $this->page.='<body><div id="header"><h1>Header section</h1></div><div id="navbar"><ul><li><a href="#" title="Link 1">Link 1</a></li><li><a href="#" title="Link 2">Link 2</a></li><li><a href="#" title="Link 3">Link 3</a></li><li><a href="#" title="Link 4">Link 4</a></li><li><a href="#" title="Link 5">Link 5</a></li><li><a href="#" title="Link 6">Link 6</a></li></ul></div><div id="leftcol"><h1>Left column</h1></div><div id="centercol"><h1>Center column</h1></div><div id="rightcol"><h1>Right column</h1></div>';
     }
     public function doFooter(){
         $this->page.='<div id="footer"><h1>Footer section</h1></div></body></html>';
     }
     public function getPage(){
         return $this->page;
     }
     public function getControllerStyle(){
         return $this->controllerStyle;
     }
}


Czy tak powinno się tworzyć klasy widoku czy jest na to może inny lepszy sposób?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
wlamywacz
post
Post #2





Grupa: Zarejestrowani
Postów: 535
Pomógł: 27
Dołączył: 3.05.2005

Ostrzeżenie: (20%)
X----


Dołączę się do tematu gdyż sam napotkałem na tym etapie pewien problem odnośnie widoku moja classa view:
  1. <?php
  2. class view {
  3.  
  4. private $content;
  5.  
  6. public function __construct() {
  7.  
  8. $this->template = 'standard';
  9.  
  10. }
  11.  
  12. public function setTemplate($template) {
  13.  
  14. $this->template = $template;
  15.  
  16. }
  17.  
  18. public function setContent($content) {
  19.  
  20. $this->content = $content;
  21.  
  22. }
  23.  
  24. public function show() {
  25.  
  26. $content = new Smarty();
  27. $content->templae_dir = FOLDER;
  28. $content->compile_dir = FOLDER . 'compile/';
  29. $content->cache_dir = FOLDER . 'cache/';
  30. $content->caching = 0;
  31. $content->error_reporting = E_ALL; 
  32. $content->assign( 'content' , $this->content);
  33. $content->assign( 'template' , $this->template);
  34. $content->display($this->template.'/template.tpl');
  35.  
  36. }
  37.  
  38. public function newsStartPage($array, $pager, $logined) {
  39.  
  40. $content = new Smarty();
  41. $content->template_dir = FOLDER;
  42. $content->compile_dir = FOLDER . 'compile/';
  43. $content->cache_dir = FOLDER . 'cache/cache_inne/';
  44. $content->caching = 0;
  45. $content->error_reporting = E_ALL; 
  46. $content->assign( 'news' , $array);
  47. $content->assign( 'pager' , $pager);
  48. return $content->fetch($this->template.'/news.tpl');
  49.  
  50. }
  51.  
  52. public function news($array, $msg, $comments, $logined) {
  53.  
  54. $content = new Smarty();
  55. $content->template_dir = FOLDER;
  56. $content->compile_dir = FOLDER . 'compile/';
  57. $content->cache_dir = FOLDER . 'cache/cache_inne/';
  58. $content->caching = 0;
  59. $content->error_reporting = E_ALL; 
  60. $content->assign( 'new' , $array);
  61. $content->assign( 'msg' , $msg);
  62. $content->assign( 'comments' , $comments);
  63. return $content->fetch($this->template.'/new.tpl');
  64.  
  65. }
  66. }
  67. ?>


Chodzi dokładnie o funkcję show() przekazuje do niej przez setContent() treść którą ma wyświetlić z innych klas (news itp.). Jednak w template.tpl będzie jeszcze menu którego struktura jest zależna od danych w bazie, jak przekazać to do show() te dane? Chyba rozumiecie w czym problem?

Ten post edytował wlamywacz 16.07.2008, 15:36:27
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 03:27