Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Routing, strona się rozsypuje
lDoran
post 15.03.2011, 09:50:44
Post #1





Grupa: Zarejestrowani
Postów: 172
Pomógł: 13
Dołączył: 15.11.2009

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


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>
Go to the top of the page
+Quote Post
erix
post 15.03.2011, 21:20:20
Post #2





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




http://eriz.pcinside.pl/weblog/mod_rewrite...wiazac-208.html


--------------------

ZCE :: Pisząc PW załączaj LINK DO TEMATU i TYLKO w sprawach moderacji :: jakiś błąd - a TREŚĆ BŁĘDU? :: nie ponaglaj z odpowiedzią via PW!
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 14.07.2025 - 06:51