Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> MVC - widok
Apo
post
Post #1





Grupa: Zarejestrowani
Postów: 426
Pomógł: 1
Dołączył: 2.10.2005

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


Witam

Zastanawiałem się ostatnio nad implemenacją widoku w moim frameworku. Dotychczas nie tworzyłem osobnych klas dla widoku tylko robiłem tak jak jest w ZF:

  1. <?php
  2.  
  3. class Controller_View extends Controller {
  4.  
  5. public function showComentsAction()
  6. {
  7. $view = new View(); // poprostu prosty parser szablonów
  8. $view->imie = "Marek"; // assign
  9. $view->render('szablon'); // wygenerowanie widoku i przekazanie do zmiennej w HttpResponse
  10. }
  11.  
  12. }
  13. ?>


Ale zauważyłem że dużo osób tworzy osobne klasy dla widoku np:

  1. <?php
  2.  
  3. class News_View extends View {}
  4.  
  5. ?>


Czy moglibyście wyjaśnić jakieś plusy trzymania widoków w osobnych klasach :?: (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
envp
post
Post #2





Grupa: Zarejestrowani
Postów: 359
Pomógł: 1
Dołączył: 16.04.2006
Skąd: Łódź

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


  1. <?php
  2. class DoSmthView extends HtmlView
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7.  
  8. $this->setTemplate('DoSmth');
  9.  
  10. }
  11. }
  12. ?>


Potrzebujessz na pdf dziedziczysz po PDFView

aha parent::__construct():

  1. <?php
  2. ...
  3. private $_sTemplate;
  4. private $_aStyleSheets;
  5.  
  6. public function __construct()
  7. {
  8. $this->_aStyleSheets = array();
  9. }
  10. ...
  11. ?>


Dorzuce kontroler jesli chcesz (takie nei wiadomo co):

  1. <?php
  2. class DoSmth extends Controller
  3. {
  4.  
  5.  
  6. public function _index(){
  7.  
  8.  
  9. $oView = $this->getView( 'DoSmth');
  10. $oModel = $this->getModel('DoSmth');
  11.  
  12. $oView->setAttribute('all',$oModel->showMeAll());
  13. $oView->setAttribute('imie', $this->imie);
  14. return($oView);
  15. }
  16.  
  17. public function Login()
  18. {
  19. $oInput = $this->getInputData();
  20.  
  21. if(!$oInput->getParameter('user_name',2) ||
  22.  !$oInput->getParameter('password',2))
  23. {
  24. $this->pushNextAction('Login');
  25. return;
  26. }
  27. else
  28. {
  29. if(($oInput->getParameter('password',2)) == 'ppp')
  30. {
  31. $oUser = new User;
  32. $aGroups[] = 'administrator';
  33. $oUser->setGroups($aGroups);
  34. $oUser->setAuthenticated();
  35. $this->pushNextAction('DoSmth','_index');
  36. return;
  37. }
  38. else
  39. {
  40. $this->pushNextAction('Login');
  41. return;
  42. }
  43.  
  44. }
  45. }
  46.  
  47.  
  48.  
  49.  
  50. }
  51. ?>
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: 27.12.2025 - 06:46