Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Zbędne wyświetlenie tablicy 2 raz
!*!
post
Post #1





Grupa: Zarejestrowani
Postów: 4 298
Pomógł: 447
Dołączył: 16.11.2006

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


  1. class Lang
  2. {
  3. private $prefix;
  4. private $lines = array();
  5.  
  6. private static $instance = false;
  7.  
  8. public function __construct($prefix)
  9. {
  10. $this->prefix = $prefix;
  11. $this-> set_lang();
  12. } // end __construct
  13.  
  14. private function instance()
  15. {
  16. //echo $prefix;
  17. if(self::$instance == false)
  18. {
  19. self::$instance = new Lang(DEFAULT_LANG);
  20. }
  21. return self::$instance;
  22. } // end instance
  23.  
  24. private function set_lang()
  25. {
  26. if(isset($_GET['lang']))
  27. {
  28. //echo $prefix;
  29. $this->prefix = strtolower($_GET['lang']);
  30. //$_SESSION['lang'] = $this->prefix;
  31. //echo 'wybrano:.....'.$this->prefix;
  32. }
  33. elseif(isset($_SESSION['lang']))
  34. {
  35.  
  36. $this->prefix = strtolower($_SESSION['lang']);
  37. $_SESSION['lang'] = $this->prefix;
  38. }
  39. else
  40. {
  41. $this->prefix = strtolower(DEFAULT_LANG);
  42. }
  43.  
  44. $this-> load_lang_file();
  45. } // end set_lang
  46.  
  47. private function load_lang_file()
  48. {
  49.  
  50. if(file_exists('./lang/'.$this->prefix.'.lang'.EXT))
  51. {
  52. //echo 'istnieje';
  53. include './lang/'.$this->prefix.'.lang'.EXT;
  54. $this->lines = $lang;
  55. echo '<pre>';
  56. print_r($this->lines);
  57. }
  58. } // end load_lang_file
  59.  
  60. public static function get($key = false)
  61. {
  62. //var_dump($key);
  63. //echo '<span style=color:red>'.$key.'</span>';
  64. //return vsprintf(self::instance()-> lines[$key], $params);
  65.  
  66. if(isset(self::instance()->lines[$key]))
  67. {
  68. return vsprintf(self::instance()-> lines[$key], false);
  69. }
  70. else
  71. {
  72. return false;
  73. }
  74.  
  75. }// end get
  76.  
  77. } // end class Lang


Dlaczego kod

  1. echo '<pre>';
  2. print_r($this->lines);


w metodzie load_lang_file() wyświetla dwa razy tą samą tablice?

Plik z tłumaczeniem wygląda tak:

  1. $lang = array(
  2. 'mobile_version' => 'wersja mobilna',
  3. 'site_map' => 'mapa witryny',
  4. 'contact' => 'kontakt'
  5. );


Ten post edytował !*! 8.09.2011, 08:05:08


--------------------
Nie udzielam pomocy poprzez PW i nie mam GG.
Niektóre języki programowania, na przykład C# są znane z niezwykłej przenośności (kompatybilność ze wszystkimi wersjami Visty jest wiele warta).
Go to the top of the page
+Quote Post

Posty w temacie


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: 19.08.2025 - 09:15