Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Routing
Forum PHP.pl > Forum > PHP
lDoran
Witam napisałem taką klasę routingu
  1. <?php
  2.  
  3. class Application_Routing_Data implements Application_Routing_Data_Interface {
  4. public function __construct() {
  5. $sUrl = $this->removeApplicationPathName();
  6. /* Ustawienie domyślnych wartości parametrów */
  7. $this->setParameters('Module', null, null);
  8. $this->setParameters('Action', null, null);
  9. $this->setParameters('Value', null, null);
  10.  
  11. $this->parseApplicationUrl($sUrl);
  12. }
  13.  
  14. /* Metoda usuwająca z adresu url nazwę katalogu strony */
  15. private function removeApplicationPathName() {
  16. $str = explode(APP_WEB_PATH, $_SERVER['REQUEST_URI']);
  17. return $str[1];
  18. }
  19.  
  20. /* Metoda parsująca adres url */
  21. private function parseApplicationUrl($sUrl) {
  22. $counter = 0;
  23. $str = explode('/', $sUrl);
  24.  
  25. /* Stworzenie składowej tablicy dla pierwszych zmiennych adresu URL */
  26. if(preg_match('/[a-zA-z0-9]+[\-|\,]/', $str[1])) {
  27. $aStr = explode(',', $str[1]);
  28. foreach($aStr as $value) {
  29. $aStr[$counter] = explode('-', $value);
  30. $counter++;
  31. }
  32.  
  33. for($i = 0; $i < count($aStr); $i++) {
  34. $this->setParameters('Value', $aStr[$i][0], $aStr[$i][1]);
  35. }
  36. /* Stworzenie tablicy parametrów dla adresu URL moduł/akcja/zmienne */
  37. } else {
  38. if(strlen($str[0]) > 0)
  39. $this->setParameters('Module', null, $str[0]);
  40.  
  41. if(strlen($str[1]) > 0)
  42. $this->setParameters('Action', null, $str[1]);
  43.  
  44. $aStr = explode(',', $str[2]);
  45. foreach($aStr as $value) {
  46. $aStr[$counter] = explode('-', $value);
  47. $counter++;
  48. }
  49.  
  50. for($i = 0; $i < count($aStr); $i++) {
  51. $this->setParameters('Value', $aStr[$i][0], $aStr[$i][1]);
  52. }
  53. }
  54. }
  55.  
  56.  
  57. /* Metody dostępu */
  58. public function setParameters($sFirstIndexName = null, $sSecondIndexName = null, $value = null) {
  59. if($sFirstIndexName != null && $sSecondIndexName == null) {
  60. $this->_aParameters[$sFirstIndexName] = $value;
  61. } else if($sFirstIndexName != null && $sSecondIndexName != null) {
  62. $this->_aParameters[$sFirstIndexName][$sSecondIndexName] = $value;
  63. }
  64. }
  65.  
  66. public function getParameters($sFirstIndexName = null, $sSecondIndexName = null) {
  67. if($sFirstIndexName != null && $sSecondIndexName != null) {
  68. return $this->_aParameters[$sFirstIndexName][$sSecondIndexName];
  69. } else if($sFirstIndexName != null && $sSecondIndexName == null) {
  70. return $this->_aParameters[$sFirstIndexName];
  71. } else if($sFirstIndexName == null && $sSecondIndexName == null) {
  72. return $this->_aParameters;
  73. }
  74. }
  75.  
  76. /* Prywatne składowe */
  77. private $_aParameters;
  78. }
  79. ?>
  80.  


Przy wpisaniu url: http://localhost/CMS/administrator/slowaKluczowe strona wyświetla się normalnie jednak po podaniu zmiennych w url: http://localhost/CMS/administrator/slowaKl...z-slowaKluczowe strona się rozsypuje, nie wiem w czym tkwi problem.
Mój .htaccess
  1. RewriteEngine on
  2.  
  3. <IfModule mod_rewrite.c>
  4. RewriteBase /
  5. RewriteRule ^index\.php$ - [L]
  6. RewriteCond %{REQUEST_FILENAME} !-f
  7. RewriteCond %{REQUEST_FILENAME} !-d
  8. RewriteRule . /CMS/index.php [L]
  9. </IfModule>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.