Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> MVC, problem z kontrolerem
Raven1122
post
Post #1





Grupa: Zarejestrowani
Postów: 369
Pomógł: 2
Dołączył: 1.11.2010

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


Witam, mam problem z Kontrolerem MVC, otóż nie otrzymuje od niego żadnego odzewu ;s


router.php:

  1. <?php
  2.  
  3. class Router{
  4.  
  5. protected $baseURL;
  6. protected $parsedURL;
  7. protected $modelpath;
  8. protected $id;
  9. public $model;
  10.  
  11. public function __construct(){
  12. //Ustawienie ścieżki do modeli
  13. $this->baseURL = "/inc/models/";
  14. return $this->baseURL;
  15. }
  16.  
  17.  
  18. public function _parseURL($model){
  19. //Zapisanie tablicy z podzielonym adresem URL
  20. $this->parsedURL = explode('/', $model);
  21. if(ctype_alpha($this->parsedURL[1])){
  22. $this->modelpath = $this->baseURL . $this->parsedURL[1] . '.php';
  23.  
  24. if(array_key_exists(2, $this->parsedURL) && $this->parsedURL[2] != ''){
  25. $this->id = $this->parsedURL[2];
  26. $this->model = $this->parsedURL[2];
  27. return $this->id;
  28. return $this->modelpath;
  29. return $this->model;
  30. //Próba odzewu
  31. echo 'model';
  32.  
  33. }
  34. else{
  35. $this->id = null;
  36. $this->model = $this->parsedURL[2];
  37. return $this->id;
  38. return $this->modelpath;
  39. return $this->model;
  40. //Próba odzewu
  41. echo 'id';
  42. }
  43. }
  44. else{
  45. //header("Location:./index.php");
  46. }
  47. }
  48.  
  49.  
  50. public function _setRoute($model, $id){
  51. try{
  52. if(file_exist($this->modelpath)){
  53. if($id == null){
  54. include $this->modelpath;
  55. }
  56. else{
  57. include $this->modelpath.'?nid=' . $id;
  58. }
  59. }
  60. else{
  61. return false;
  62. }
  63. }
  64. catch(Exception $e){
  65. echo 'Caught exception:' . $e->getMessage();
  66. }
  67.  
  68. }
  69.  
  70.  
  71.  
  72.  
  73. }
  74.  
  75. ?>


Testowy plik model dla news:
  1. <?php
  2.  
  3. echo 'News';
  4. ?>


htaccess:
  1. RewriteEngine On
  2. RewriteCond %{REQUEST_FILENAME} !-f
  3. RewriteCond %{REQUEST_FILENAME} !-d
  4. RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php




No i wywolanie tego wszystkiego z linku http://testowyserwer.serwer.pl/news
  1. <?php
  2. function __autoload($classname){
  3. include strtolower($classname) . '.php';
  4. }
  5. $router = new Router();
  6. $router->_parseURL($_SERVER["REQUEST_URI"]);
  7. $router->_setRoute($model, $id);
  8. ?>



Po załadowaniu linku powyżej pokazuje się biała strona, nie wywołuje echo z news.php, ani z router.php

Ten post edytował Raven1122 27.06.2013, 13:50:28
Go to the top of the page
+Quote Post
CuteOne
post
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


Sprawdź error logi php'a/apache. Pewnie palnąłeś gdzieś błąd

Ten post edytował CuteOne 27.06.2013, 14:13:14
Go to the top of the page
+Quote Post
Spawnm
post
Post #3





Grupa: Moderatorzy
Postów: 4 069
Pomógł: 497
Dołączył: 11.05.2007
Skąd: Warszawa




Jaki to ma sens?
  1. return $this->id;
  2. return $this->modelpath;
  3. return $this->model;


$model i $id nie istnieją.
  1. $router->_setRoute($model, $id);
Go to the top of the page
+Quote Post
Raven1122
post
Post #4





Grupa: Zarejestrowani
Postów: 369
Pomógł: 2
Dołączył: 1.11.2010

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


Przeciez sa zdefiniowane w _parseURL i je zwracam

  1. public function _parseURL($model){
  2. //Zapisanie tablicy z podzielonym adresem URL
  3. $this->parsedURL = explode('/', $model);
  4. if(ctype_alpha($this->parsedURL[1])){
  5. $this->modelpath = $this->baseURL . $this->parsedURL[1] . '.php';
  6.  
  7. if(array_key_exists(2, $this->parsedURL) && $this->parsedURL[2] != ''){
  8. $this->id = $this->parsedURL[2];
  9. $this->model = $this->parsedURL[2];
  10. return $this->id;
  11. return $this->modelpath;
  12. return $this->model;
  13. //Próba odzewu
  14. echo 'model';
  15.  
  16. }
  17. else{
  18. $this->id = null;
  19. $this->model = $this->parsedURL[2];
  20. return $this->id;
  21. return $this->modelpath;
  22. return $this->model;
  23. //Próba odzewu
  24. echo 'id';
  25. }
  26. }


Ten post edytował Raven1122 28.06.2013, 18:07:18
Go to the top of the page
+Quote Post
erix
post
Post #5





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




Ale przecież pierwszy return przerywa Ci działanie funkcji...


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

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 Aktualny czas: 21.08.2025 - 08:43