Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Warning! do poprawy, Wyświetla się warning. Pomoc w poprawie
r3pilc3
post
Post #1





Grupa: Zarejestrowani
Postów: 35
Pomógł: 0
Dołączył: 22.07.2012

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


Witam
Mam stronę napisaną w php (na zasadzie frameworka czyli wiele plików.php połączonych ze sobą), która poprawnie działa w XAMPP 1.7.7 (php wersja 5.3.8).
Pragnę zainstalować na swoim PC, najnowszy XAMPP 1.8.0, który ma wersję php 5.4.4.
(i oto moja obietnica dla wtajemniczonych z poprzedniego tematu - to już jest ostatnia wersja XAMPPa na jaką chce zamienić i jak pojawi się nowsza wersja to już nie będę zamieniał na nowszego XAMPP i od nowa prosił o pomoc)

Napotykam w sowiej stronie następujące błędy:

1) Strona główna mojej strony zawiera 2 (strzelam krytyczne) błędy:
http://i48.tinypic.com/349c45x.png

2) posiadam w projekcie tylko stronę główną oraz stronę logowania w której występują następujące błędy:
http://i45.tinypic.com/287jl8m.png


Proszę bardzo o pomoc w rozwiązaniu tych błędów.

Oto plik controller_base.php:
(błędy w 13 i 17 linii)
  1. <?php
  2. Abstract Class Controller_Base {
  3. protected $registry;
  4. function __construct($registry, $models, $addons, $layout, $controller) {
  5. $this->registry = $registry;
  6. $this->session = $registry->session;
  7. $this->error = $registry->error;
  8. $this->text = $registry->text;
  9. $this->router = $registry->router;
  10. $this->template = $registry->template;
  11. $this->db = $registry->db;
  12. foreach($models as $model){
  13. $this->model->$model = $registry->model->$model;
  14. }
  15. if($addons)
  16. foreach($addons as $addon){
  17. $this->addon->$addon = $registry->addon->$addon;
  18. }
  19. $this->template->layout = $layout;
  20. $this->here = $controller;
  21. }
  22. abstract function index($args=null,$post=null);
  23. function addon($addon){
  24. return 'http://'.server_addr.site_addr.'core/addons/'.$addon;
  25. }
  26. }
  27. ?>


plik: router.php:
(błędy w 118 i 131 linii)
  1. <?php
  2.  
  3. Class Router {
  4. private $registry;
  5. private $path;
  6. private $args = array();
  7.  
  8.  
  9. function __construct($registry) {
  10. $this->registry = $registry;
  11. }
  12.  
  13.  
  14. function setPath($path) {
  15. $path .= DIRSEP;
  16.  
  17. if (is_dir($path) == false) {
  18.  
  19. throw new Exception ('Invalid controller path: `' . $path . '`');
  20. }
  21.  
  22. $this->path = $path;
  23.  
  24. }
  25.  
  26.  
  27.  
  28. private function getController(&$file, &$controller, &$action, &$args) {
  29. $route = (empty($_GET['route'])) ? '' : $_GET['route'];
  30. if (empty($route)) { $route = 'home'; }
  31.  
  32. // Get separate parts
  33. $route = trim($route, '/\\');
  34. $parts = explode('/', $route);
  35. // Find right controller
  36. $cmd_path = $this->path;
  37. foreach ($parts as $part) {
  38. $fullpath = $cmd_path . $part;
  39.  
  40. // Is there a dir with this path?
  41. if (is_dir($fullpath)) {
  42. $cmd_path .= $part . DIRSEP;
  43. array_shift($parts);
  44. continue;
  45. }
  46.  
  47. // Find the file
  48. if (is_file($fullpath . iext)) {
  49. $controller = $part;
  50. array_shift($parts);
  51. break;
  52. }
  53. }
  54.  
  55. if (empty($controller)) { $controller = 'home'; };
  56.  
  57. // Get action
  58. $action = array_shift($parts);
  59. if (empty($action)) { $action = 'index'; }
  60.  
  61. $file = $cmd_path . $controller . iext;
  62. $args = $parts;
  63. }
  64.  
  65.  
  66.  
  67. function delegate() {
  68. // Analyze route
  69.  
  70. $this->getController($file, $controller, $action, $args);
  71. // File available?
  72. $controller_name=$controller;
  73. if (is_readable($file) == false) {
  74. die ('404 - Controller File Not Found');
  75. }
  76.  
  77. // Include the file
  78. include ($file);
  79. // Initiate the class
  80. $class = 'Controller_' . $controller;
  81.  
  82.  
  83. /// LANGUAGE
  84. if($controller=="admin")
  85. $name='pl';
  86. else
  87. $name=$_SESSION['language'];
  88. end;
  89.  
  90. if($name=="") $name="eng";
  91.  
  92. $mfile=site_path . 'views' . DIRSEP . 'texts' . DIRSEP . $name . iext;
  93.  
  94. if (is_readable($mfile) == false) {
  95. die ('404 - Texts File Not Found: '.$mfile);
  96. }
  97.  
  98. include($mfile);
  99. $text_name='Text_'.$name;
  100.  
  101. $text = new $text_name($this->registry);
  102. $this->registry->text = $text;
  103.  
  104. ////////////
  105.  
  106. if($addons)
  107. foreach($addons as $addon){
  108. $mfile=core_path . 'addons' . DIRSEP .$addon . iext;
  109.  
  110. if (is_readable($mfile) == false) {
  111. die ('404 - Addon File Not Found');
  112. }
  113.  
  114. include($mfile);
  115. $addon_name='Addon_' . $addon;
  116.  
  117. $addon2 = new $addon_name($this->registry);
  118. $this->registry->addon->$addon = $addon2;
  119. }
  120.  
  121. foreach($models as $name){
  122. $mfile=site_path . 'models' . DIRSEP . $name . iext;
  123. if (is_readable($mfile) == false) {
  124. die ('404 - Model File Not Found');
  125. }
  126.  
  127. include($mfile);
  128. $model_name='Model_' . $name;
  129.  
  130. $model = new $model_name($this->registry);
  131. $this->registry->model->$name = $model;
  132. }
  133.  
  134.  
  135. $controller = new $class($this->registry, $models, $addons, $layout, $controller);
  136.  
  137.  
  138. // Action available?
  139. if (is_callable(array($controller, $action)) == false) {
  140.  
  141. $this->redirect('home/deadend/'.$controller_name.'/'.$action);
  142. die ('404 - Controller Action Not Found');
  143. }
  144.  
  145. // Run action
  146. if(is_callable(array($controller, 'BeforeFilter')) == true)
  147. $controller->BeforeFilter($action,$controller_name,$args,$_POST);
  148.  
  149. $controller->$action($args,$_POST);
  150. }
  151.  
  152. function redirect($route){
  153. header("Location: ".site_addr.$route);
  154. }
  155.  
  156.  
  157.  
  158. }
  159.  
  160. ?>


Proszę o pomoc co dokładnie znaczą te komunikat i co trzeba w takim wypadku podjąć za kroki... (nie chodzi mi o wyłożenie wszystkiego na tacy - tylko chociaż pomoc w nakierowaniu mnie na właściwy trop próby poprawy)

-Opcja wyłączenia błędów:
error_reporting ('E_ALL ^E_DEPRECATED ^E_NOTICE');
Odpada, ponieważ mój projekt musi być OK. Ale jak ją włączę to nie ma niepożądanych efektów na stronie.

Ten post edytował r3pilc3 29.07.2012, 11:40:15
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
r3pilc3
post
Post #2





Grupa: Zarejestrowani
Postów: 35
Pomógł: 0
Dołączył: 22.07.2012

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


Witam.
Jak wpisałem w pliku router.php w odpowiednim miejscu:
  1. $this->registry->addon->$addon= new $addon_name($this->registry);

Nic się nie poprawiło ani żaden inny komunikat się nie wyświetlił.
Musimy w poprawie tego pliku uwzględnić oprócz linii: 118 i 131) też linię: 88, 107 i 135. Już piszę dlaczego.

Edit:
Zaaczne od początku teraz ok wytłumaczę.
Mam stronę na zasadzie frameworka wiele plików.php połączonych ze sobą oraz baza danych.
Projekt składa się tylko ze strony głównej oraz podstrony przeznaczonej wyłącznie dla administratora.
Pragnę swój projekt mieć w XAMPP 1.8.0, który posiada php 5.4.4.
Jednak wraz z nowszą wersją php napotykam następujące problemy.

Na stronie głównej wyświetlają mi się 2 błędy:
-Warning: Creating default object from empty value in C:\xampp\htdocs\Sklep_jubilerski\core\classes\router.php on line 131
-Warning: Creating default object from empty value in C:\xampp\htdocs\Sklep_jubilerski\core\classes\controller_base.php on line 13
http://i49.tinypic.com/edkxw.png
Na stronie logowania do panelu administracyjnego mam te same 2 błędy co na stronie głównej oraz 2 dodatkowe:
-Warning: Creating default object from empty value in C:\xampp\htdocs\Sklep_jubilerski\core\classes\router.php on line 118
-Warning: Creating default object from empty value in C:\xampp\htdocs\Sklep_jubilerski\core\classes\controller_base.php on line 17
http://i50.tinypic.com/24meu79.png

Podsumowując mam 4 Warningi przez które strona nie wyświetla mi się prawidłowo.
Aby głębiej przeanalizować błędy postanowiłem w pliku index.php dodać kod pełnego raportowania błędów:
  1. error_reporting(E_ALL | E_STRICT);


Teraz na stronie głównej mam:
http://i48.tinypic.com/29f5fko.png
A na stronie logowania mam:
http://i45.tinypic.com/mihs2q.png
*Dzięki dodaniu w swój kod, kodu pełnego raportowania błędów to wyświetlają mi się dodatkowe błędy, którymi teraz się nie będziemy zajmować.
**Zajmiemy się tylko tymi dodatkowymi błędami, które są w tych samych 2 plikach co wyświetlające się błędy bez włączenia pełnego raportowania błędów, ponieważ mogą mieć ze sobą coś wspólnego!
--------------------------------
Plik controller_base.php wyświetlał 2 Warningi i jak włączyłem pełne raportowanie błędów to nic nie doszło do tego pliku. Więc w tym pliku controller_base.php są błędy w linii: 13 i 17.
Oto kod pliku controller_base.php:
  1. <?php
  2. Abstract Class Controller_Base {
  3. protected $registry;
  4. function __construct($registry, $models, $addons, $layout, $controller) {
  5. $this->registry = $registry;
  6. $this->session = $registry->session;
  7. $this->error = $registry->error;
  8. $this->text = $registry->text;
  9. $this->router = $registry->router;
  10. $this->template = $registry->template;
  11. $this->db = $registry->db;
  12. foreach($models as $model){
  13. $this->model->$model = $registry->model->$model; //linia 13
  14. }
  15. if($addons)
  16. foreach($addons as $addon){
  17. $this->addon->$addon = $registry->addon->$addon; //linia17
  18. }
  19. $this->template->layout = $layout;
  20. $this->here = $controller;
  21. }
  22. abstract function index($args=null,$post=null);
  23. function addon($addon){
  24. return 'http://'.server_addr.site_addr.'core/addons/'.$addon;
  25. }
  26. }
  27. ?>

------------------------------------------
Natomiast plik router.php wyświetlał 2 Warningi w linii: 118 i 131.
Gdy dodałem pełne raportowanie błędów to doszły błędy w liniach: 88, 107 i 135.
Oto kod pliku router.php:
  1. <?php
  2.  
  3. Class Router {
  4.  
  5. private $registry;
  6. private $path;
  7. private $args = array();
  8.  
  9. function __construct($registry) {
  10. $this->registry = $registry;
  11. }
  12.  
  13.  
  14.  
  15. function setPath($path) {
  16. $path .= DIRSEP;
  17.  
  18. if (is_dir($path) == false) {
  19.  
  20. throw new Exception ('Invalid controller path: `' . $path . '`');
  21. }
  22.  
  23. $this->path = $path;
  24.  
  25. }
  26.  
  27.  
  28. private function getController(&$file, &$controller, &$action, &$args) {
  29. $route = (empty($_GET['route'])) ? '' : $_GET['route'];
  30. if (empty($route)) { $route = 'home'; }
  31.  
  32. // Get separate parts
  33. $route = trim($route, '/\\');
  34. $parts = explode('/', $route);
  35. // Find right controller
  36. $cmd_path = $this->path;
  37. foreach ($parts as $part) {
  38. $fullpath = $cmd_path . $part;
  39.  
  40. // Is there a dir with this path?
  41. if (is_dir($fullpath)) {
  42. $cmd_path .= $part . DIRSEP;
  43. array_shift($parts);
  44. continue;
  45. }
  46.  
  47. // Find the file
  48. if (is_file($fullpath . iext)) {
  49. $controller = $part;
  50. array_shift($parts);
  51. break;
  52. }
  53. }
  54.  
  55. if (empty($controller)) { $controller = 'home'; };
  56.  
  57. // Get action
  58. $action = array_shift($parts);
  59. if (empty($action)) { $action = 'index'; }
  60.  
  61. $file = $cmd_path . $controller . iext;
  62. $args = $parts;
  63. }
  64.  
  65.  
  66.  
  67. function delegate() {
  68. // Analyze route
  69.  
  70. $this->getController($file, $controller, $action, $args);
  71. // File available?
  72. $controller_name=$controller;
  73. if (is_readable($file) == false) {
  74. die ('404 - Controller File Not Found');
  75. }
  76.  
  77. // Include the file
  78. include ($file);
  79. // Initiate the class
  80. $class = 'Controller_' . $controller;
  81.  
  82.  
  83. /// LANGUAGE
  84. if($controller=="admin")
  85. $name='pl';
  86. else
  87. $name=$_SESSION['language'];
  88. end; //linia 88
  89.  
  90. if($name=="") $name="eng";
  91.  
  92. $mfile=site_path . 'views' . DIRSEP . 'texts' . DIRSEP . $name . iext;
  93.  
  94. if (is_readable($mfile) == false) {
  95. die ('404 - Texts File Not Found: '.$mfile);
  96. }
  97.  
  98. include($mfile);
  99. $text_name='Text_'.$name;
  100.  
  101. $text = new $text_name($this->registry);
  102. $this->registry->text = $text;
  103.  
  104. ////////////
  105.  
  106. if($addons)
  107. foreach($addons as $addon){ //linia 107
  108. $mfile=core_path . 'addons' . DIRSEP .$addon . iext;
  109.  
  110. if (is_readable($mfile) == false) {
  111. die ('404 - Addon File Not Found');
  112. }
  113.  
  114. include($mfile);
  115. $addon_name='Addon_' . $addon;
  116.  
  117. $addon2 = new $addon_name($this->registry);
  118. $this->registry->addon->$addon = $addon2; //linia 118
  119. }
  120.  
  121. foreach($models as $name){
  122. $mfile=site_path . 'models' . DIRSEP . $name . iext;
  123. if (is_readable($mfile) == false) {
  124. die ('404 - Model File Not Found');
  125. }
  126.  
  127. include($mfile);
  128. $model_name='Model_' . $name;
  129.  
  130. $model = new $model_name($this->registry);
  131. $this->registry->model->$name = $model; //linia 131
  132. }
  133.  
  134.  
  135. $controller = new $class($this->registry, $models, $addons, $layout, $controller); //linia 135
  136.  
  137.  
  138. // Action available?
  139. if (is_callable(array($controller, $action)) == false) {
  140.  
  141. $this->redirect('home/deadend/'.$controller_name.'/'.$action);
  142. die ('404 - Controller Action Not Found');
  143. }
  144.  
  145. // Run action
  146. if(is_callable(array($controller, 'BeforeFilter')) == true)
  147. $controller->BeforeFilter($action,$controller_name,$args,$_POST);
  148.  
  149. $controller->$action($args,$_POST);
  150. }
  151.  
  152. function redirect($route){
  153. header("Location: ".site_addr.$route);
  154. }
  155. }
  156. ?>


------------------------------
------------------------------
1 błąd 'Notice' rozwiązałem w pliku router.php. Powiedźcie jak wiecie czy źle zrobiłem ale jestem pewien, że dobrze, skoro jest komunikat:
Notice: Use of undefined constant end - assumed 'end' in C:\xampp\htdocs\Sklep_jubilerski\core\classes\router.php on line 88
To należy w linii 88 co się znajduje: end; poprawić na: 'end';
Zapisałem zmiany i już ten błąd się nie wyświetla na stronie głównej i na stronie logowania.
Proszę o pomoc w poprawieniu pozostałych błędów.

ps. to jest FW 5.0

Zawiadomienia możemy pominąć, ponieważ już je rozwiązałem.

Proszę o pomoc w poprawie 4 błędów.

Ten post edytował r3pilc3 30.07.2012, 16:33:18
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: 17.10.2025 - 16:16