Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]namespace i use - Jak z tego korzystać?
Johnas
post
Post #1





Grupa: Zarejestrowani
Postów: 650
Pomógł: 16
Dołączył: 5.07.2010
Skąd: Ściśle Tajne

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


Witam, pisząc własny skrypt szkolę się z używania namespace i use, ale dostaje błędy że nie można znaleźć pliku... nie wiem jak z tego korzystać, czy mógłby ktoś to w prosty sposób opisać?

mam folder global i posiadam tam wszystkie klasy i kontrolery, ale nie wiem jak w global.php który nie jest klasą zaincludować te pliki przy użyciu use.. w root jaki powinien być namespace ? nie rozumiem tego... mam wielkie braki w programowaniu, które próbuje nadrobić, ale mi nie wychodzi (IMG:style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Johnas
post
Post #2





Grupa: Zarejestrowani
Postów: 650
Pomógł: 16
Dołączył: 5.07.2010
Skąd: Ściśle Tajne

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


już tłumaczę o co mi chodzi. Mam klasę Engine gdzie jest wszystko ładowane między innymi połączenie z bazą danych oraz mam klasę Configuration która pobiera konfiguracje:

  1. <?php
  2.  
  3. class Configuration
  4. {
  5. /** @var id */
  6. public $id;
  7.  
  8. /** @var key */
  9. public $key;
  10.  
  11. /** @var value */
  12. public $value;
  13.  
  14. /** @var array */
  15. public $configuration = array();
  16.  
  17. /** Constructor */
  18. public function __construct($key = null) {
  19. global $engine;
  20. if ($key == null) {
  21.  
  22. $array = $engine->mysql->get($engine->prefix."config");
  23.  
  24. foreach ($array as $data) {
  25. $this->configuration[$data["name"]] = $data["value"];
  26. }
  27.  
  28. return $this->configuration;
  29. } else {
  30. return $this->getValueByKey($key);
  31. }
  32.  
  33. }
  34.  
  35. /**
  36.   * @param id $id
  37.   */
  38. public function setId(id $id): void
  39. {
  40. $this->id = $id;
  41. }
  42.  
  43. /**
  44.   * @return id
  45.   */
  46. public function getId(): id
  47. {
  48. return $this->id;
  49. }
  50.  
  51. /**
  52.   * @return key
  53.   */
  54. public function getKey(): key
  55. {
  56. return $this->key;
  57. }
  58.  
  59. /**
  60.   * @param key $key
  61.   */
  62. public function setKey(key $key): void
  63. {
  64. $this->key = $key;
  65. }
  66.  
  67. /**
  68.   * @return value
  69.   */
  70. public function getValue(): value
  71. {
  72. return $this->value;
  73. }
  74.  
  75. /**
  76.   * @param value $value
  77.   */
  78. public function setValue(value $value): void
  79. {
  80. $this->value = $value;
  81. }
  82.  
  83. public function save() {
  84. global $engine;
  85.  
  86. $data = array("name" => $this->key,
  87. "value" => $this->value);
  88. if ($this->getValueByKey($this->key)) {
  89. $engine->mysql->where("name", $this->key);
  90. $id = $engine->mysql->update($engine->prefix."config", $data);
  91. } else {
  92.  
  93. $id = $engine->mysql->insert($engine->prefix."config", $data);
  94. }
  95.  
  96. if (isset($id) && $id > 0)
  97. return true;
  98. else
  99. return false;
  100. }
  101.  
  102. /**
  103.   * @param key $key
  104.   */
  105. public function getValueByKey($key)
  106. {
  107. global $engine;
  108.  
  109. $engine->mysql->where("name", $key);
  110. $ret = $engine->mysql->getOne($engine->prefix."config");
  111.  
  112. $this->id = $ret["id"];
  113. $this->key = $ret["name"];
  114. $this->value = $ret["value"];
  115. if (isset($this->id) && $this->id > 0)
  116. return true;
  117. else
  118. return false;
  119. }
  120. }


Potrzebuje pobrać konfigurację z bazy danych w konstrukcji Engine, ale bez konstrukcji Engine klasa Configuration nie ma danych o mysql bo znajduje się ona w Engine i teraz nie wiem jak to ze sobą połączyć... czy jest nawet taka możliwość
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: 12.10.2025 - 20:06