Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] problemz globalnymi w funkcjach
Forum PHP.pl > Forum > Przedszkole
troian
Witam mam problem z odczytywaniem globalncyh z funkcji. poniżej załączam kod plików.
  1. #PLIK INDEX.PHP WCZYTUJE PLIK LOAD.PHP.
  2.  
  3. #PLIK LOAD.PHP:
  4.  
  5. defined('CE_ENABLE_SCRIPT') or die;
  6. class load
  7. {
  8. private $web_online = web_online;
  9. public function __construct()
  10. {
  11. if(file_exists(CE_PATH_LIB . '/load_components.php'))
  12. require_once CE_PATH_LIB . '/load_components.php';
  13. else
  14. die("PL: blad wczytywania pliku <b>load_components.php</b><br>EN: Error loading file <b>load_components.php</b>");
  15.  
  16. if($this->web_online >0)
  17. if(file_exists(CE_PATH_THEMES . DIRECTORY_SEPARATOR . templates_name . '/index.php'))
  18. {
  19. require_once CE_PATH_THEMES . DIRECTORY_SEPARATOR . templates_name . '/index.php';
  20. }else{
  21. die("PL: blad wczytywania szablonu <b>" .templates_name . "</b><br>EN: Error loading themes <b>" .templates_name);
  22. }
  23. else
  24. require_once CE_PATH_THEMES . DIRECTORY_SEPARATOR . 'offline/index.php';
  25. }
  26.  
  27. }
  28.  
  29. $load = new load;
  30.  
  31. #############################################################################
  32.  
  33. JAK WIDAĆ TEN PLIK WCZYTUJE SZABLON STRONY ORAZ INNY PLIK KTÓRY ODPOWIADA ZA WCZYTYWANIE KOMPONENTÓW, PLIK LOAD_COMPONTENTS.PHP
  34.  
  35. # PLIK LOAD_COMPONTENTS.PHP
  36.  
  37. defined('CE_ENABLE_SCRIPT') or die;
  38.  
  39. class load_components
  40. {
  41. protected $com_script = "script/script.php";
  42. protected $com_config = "script/config.php";
  43. protected $script;
  44. protected $themes;
  45.  
  46. public function components($value1)
  47. {
  48. global $db, $lang;
  49. $result = $db->query("SELECT com_name,themes_name,active FROM ".WEB.".`web_components` WHERE `themes_name`=? LIMIT 1", array($value1), "fetch");
  50. if(isset($result))
  51. {
  52. define($result['com_name'] . '_' . $result['themes_name'] . '_enable', $result['active']);
  53.  
  54. $com_name = $result['com_name'];
  55. $themes_name = $result['themes_name'];
  56.  
  57. $script = CE_PATH_COMPONENTS . DIRECTORY_SEPARATOR . $com_name . DIRECTORY_SEPARATOR . $this->com_script;
  58. if(file_exists($script))
  59. {
  60. $this->script = $script;
  61. }else{
  62. $this->script = CE_PATH_COMPONENTS . DIRECTORY_SEPARATOR . $this->com_script;
  63. }
  64.  
  65. $themes = CE_PATH_COMPONENTS . DIRECTORY_SEPARATOR . $com_name . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $themes_name . '.php';
  66. $update_themes = CE_PATH_THEMES . DIRECTORY_SEPARATOR . templates_name . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . $com_name . DIRECTORY_SEPARATOR . $themes_name . '.php';
  67.  
  68. if(file_exists($themes))
  69. {
  70. if(file_exists($update_themes))
  71. {
  72. $this->themes = $update_themes;
  73. }else{
  74. $this->themes = $themes;
  75. }
  76. }else{
  77. $this->themes = CE_PATH_COMPONENTS . DIRECTORY_SEPARATOR . 'com_offline/index.php';
  78. }
  79.  
  80.  
  81. require_once $this->script;
  82. require_once $this->themes;
  83.  
  84. }
  85. }
  86.  
  87.  
  88. }
  89.  
  90. $com = new load_components;
  91.  
  92. podając nazwe komponentu wygeneruje nam adresy do wczytania po czym na samym dole mamy require_once które wczyta plik script oraz themes do tej pory wszystko dziala super.
  93.  
  94. #################################################################
  95.  
  96. LADOWANIE COMPONENTU WEWNATRZ PLIKU INDEX.PHP W SZABLONIE
  97.  
  98.  
  99. $com->components('themes_login');
  100.  
  101. ################################################################
  102. ZAWARTOSC PLIKU SCRIPT.PHP W KATALOGU COM_LOGIN
  103.  
  104. defined('CE_ENABLE_SCRIPT') or die;
  105.  
  106. class com_login
  107. {
  108. private $account_table = Array(1 => 'id',2 => 'login',3 => 'email',4 => 'cash',5 => 'social_id',6 => 'silver_expire');
  109.  
  110. public function start_login()
  111. {
  112. global $db, $lang, $start_login_massage, $start_login_status;
  113. $table = $this->account_table;
  114. if((test_input($_POST['login']) && test_input($_POST['pass'])) && !empty($_POST['login']) && !empty($_POST['pass']))
  115. {
  116. $login = clear($_POST['login']);
  117. $pass = clear($_POST['pass']);
  118. $result = $db->query("SELECT id,login,email,cash,social_id,silver_expire FROM ".ACCOUNT.".`account` WHERE `login`=? AND `password`=PASSWORD(?) LIMIT 1", array($login,$pass), "fetch");
  119. if($result)
  120. {
  121. for( $x = 1; $x <= count($table); $x++ )
  122. {
  123. $_SESSION[$table[$x]] = $result[$table[$x]];
  124. }
  125. $_SESSION['time_login'] = strtotime(date("Y-m-d H:i:s"))+60*15;
  126. header('Location: '.url() . 'konto');
  127. }else{
  128. $start_login_massage = 'login_incorrect_data_account';
  129. $start_login_status = 'error';
  130. }
  131. }else{
  132. $start_login_massage = 'login_null_incorrect_data';
  133. $start_login_status = 'error';
  134. }
  135. }
  136.  
  137. [...]
  138. }
  139. $com_login = new com_login;
  140.  
  141. # Jeżeli wykonam funkcję $com_login->start_login(); to funkcja się wykona oraz całe logowanie, jednak problem jest z GLOBAL w funkcji start_login
  142. # zmiennej $start_login_massage z pliku com_login/script.php nie mogę odczytać w pliku com_login/themes_login.php


Czy ktoś może wie jaki popełniłem błąd w kodzie? Bardzo proszę o pomoc gdyż morduje ten kod już 4 dzień i dalej nie działa tak ja bym tego chciał.
Daimos
Cytat(troian @ 30.10.2015, 12:58:28 ) *
Czy ktoś może wie jaki popełniłem błąd w kodzie? Bardzo proszę o pomoc gdyż morduje ten kod już 4 dzień i dalej nie działa tak ja bym tego chciał.

Podstawowy błąd jaki popełniłeś, to w ogóle korzystanie z global, przemyśl lepiej strukturę działania tych klas
troian
Cytat(Daimos @ 30.10.2015, 13:24:15 ) *
Podstawowy błąd jaki popełniłeś, to w ogóle korzystanie z global, przemyśl lepiej strukturę działania tych klas


Wybacz jednak od niedawna bawie się tym wink.gif Jeżeli masz jakąś sugestie lub wzorzec na którym mógł bym się oprzeć to bardzo proszę o podanie takiego wzorca / pomysłu smile.gif
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.