Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][PHP]Programowanie obiektowe, jak nie mieszać logiki z HTMLem
gargamel
post
Post #1





Grupa: Zarejestrowani
Postów: 278
Pomógł: 35
Dołączył: 25.06.2010

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


Przyszedł czas przestawić się na programowanie obiektowe, ale żeby od razu źle nie zacząć, mam pytanko.

Napisałem prostą klasę (do generowania formularzy), aby od czegoś zacząć:
  1. class formClass
  2. {
  3. public $output;
  4. public $startedGroup;
  5.  
  6. public function formGroup(){
  7. if($startedGroup){
  8. $this -> output .= "</div>\n";
  9. }
  10. $this -> output .= "<div>\n";
  11. $this -> startedGroup = true;
  12. }
  13.  
  14. public function formElement($name){
  15. $this -> output .= "<div>".$name.": <input type='text' name='".$name."' /></div>\n";
  16. }
  17.  
  18. public function printForm(){
  19. $this -> output .= "</div>\n";
  20. echo $this -> output;
  21. }
  22. }
  23.  
  24. $form = new formClass;
  25.  
  26. $form -> formGroup();
  27. $form -> formElement('imie');
  28. $form -> formElement('nazwisko');
  29. $form -> formElement('wiek');
  30.  
  31. $form -> formGroup();
  32. $form -> formElement('adres_email');
  33. $form -> formElement('telefon');
  34.  
  35. $form -> printForm();


I teraz problem... wszędzie pisze się aby nie mieszać logiki z HTMLem, a ja tu nie widzę żadnej możliwości, aby wywoływane metody nie zwracały HTMLa...
W jaki sposób powinno się prawidłowo coś takiego robić?

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: 22.08.2025 - 11:57