Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Klasa Router - pomoc w zrozumienia założenia i wykonaniu
Joachim Peters
post
Post #1





Grupa: Zarejestrowani
Postów: 196
Pomógł: 2
Dołączył: 1.03.2006

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


Witam,

Próbuje napisać klasę Router do swojego systemu, jednak chyba coś mi nie wychodzi. Proszę spojrzeć.
  1. <?php
  2.  
  3. class Router {
  4.  private $url;
  5. private $params = array();
  6.  
  7. public function __construct() {
  8. $this->url = $_SERVER['PATH_INFO'];
  9.  
  10. $this->getParams();
  11. }
  12.  
  13. // pobiera nazwę serwera
  14. public function getServerName() {
  15. return $_SERVER['HTTP_HOST'];
  16. }
  17.  
  18. public function getParams() {
  19. $this->params = explode('/', $this->url);
  20. }
  21.  
  22. // pobiera parametr o wyznaczonym id
  23. public function getParam($id) {
  24. return (isset($this->params[$id])) ? $this->params[$id] : false;
  25. }
  26.  
  27. // pobiera nazwę modułu np. news, page, download
  28. public function getModule() {
  29. return $this->getParam(0);
  30. }
  31.  
  32. // pobiera nazwę akcji np. edit, add lub delete
  33. public function getAction() {
  34. return $this->getParam(1);
  35. }
  36.  
  37. // tworzy adres URL np. wpisując createUrl('news/edit/2'); otrzymamy domena.com/index.php/news/edit/2
  38. public function createUrl($params) {
  39. return $this->getServerName().'/index.php/'.$params;
  40. }
  41. }
  42.  
  43. ?>


Czy dobrze zrozumiałem założenie tej klasy?
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: 28.09.2025 - 21:27