Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> importowanie plikow
marcio
post
Post #1





Grupa: Zarejestrowani
Postów: 2 291
Pomógł: 156
Dołączył: 23.09.2007
Skąd: ITALY-MILAN

Ostrzeżenie: (10%)
X----


WItam robie sobie taki wlasny __autoload tzn juz go mam mialem w tablicy wszystkie sciezki na sztywno i wszystko dziala jednak jak chce ladowac sciezko z konfiguracji nie dziala.

Config.php
  1. <?php
  2.  
  3. /*
  4. *******************************************
  5. |Sciezki do MVC libraries/plugins/components *
  6. *******************************************
  7. */
  8.  
  9. $configs['PathControllers'] = 'controllers/';
  10.  
  11. $configs['PathModels'] = 'models/';
  12.  
  13. $configs['PathViews'] = 'views/';
  14.  
  15. $configs['PathLibs'] = 'libraries/';
  16.  
  17. $configs['PathPlugins'] = 'plugins/';
  18.  
  19. $configs['PathModules'] = 'components/';
  20.  
  21. $configs['PathConfig'] = 'config/';
  22.  
  23.  
  24. /*
  25. ********************
  26. |Ustawienia ogolne *
  27. ********************
  28. */
  29.  
  30.  
  31. $configs['controller'] = 'Home'; //Default controller
  32.  
  33. $configs['action'] = 'Index'; //Defualt action
  34.  
  35. $configs['render'] = true; //Render = true bez echo
  36.  
  37. $configs['debug'] = 2;
  38.  
  39. /*
  40. ********************
  41. |Dane do bazy danych *
  42. ********************
  43. */
  44.  
  45. $configs['host'] = '***';
  46. $configs['login'] = '****';
  47. $configs['pwd'] = '****';
  48. $configs['db'] = '***';
  49.  
  50. return $configs;
  51. ?>

I klase import:
  1. <?php
  2. require_once('libraries/Loader.php');
  3. class Imports {
  4.  
  5.  
  6. /*
  7.   private $PathImports = array(
  8.  
  9.   $cfg -> PathControllers,
  10.   $cfg -> PathLibs,
  11.   $cfg -> PathModels,
  12.   $cfg -> PathModules.$cfg -> PathControllers,
  13.   $cfg -> PathModules.$cfg -> PathModels,
  14.   $cfg -> PathModules.$cfg -> PathViews,
  15.   $cfg -> PathPlugins.$cfg -> PathControllers,
  16.   $cfg -> PathPlugins.$cfg -> PathModels,
  17.   $cfg -> PathPlugins.$cfg -> PathViews,
  18.   $cfg -> PathConfig
  19.  
  20.  
  21.   );
  22.  
  23.   */
  24.  
  25.  
  26.  
  27.  
  28. public function __get($class) {
  29.  
  30.  
  31. foreach($this -> PathImports as $key => $imports) {
  32.  
  33. if(file_exists($imports.$class.'.php')) {
  34.  
  35. require_once($imports.$class.'.php');
  36.  
  37. }
  38.  
  39. else if(file_exists($imports.$class.'_Model.php')) {
  40.  
  41. require_once($imports.$class.'_Model.php');
  42.  
  43. }
  44.  
  45. }
  46.  
  47. if(class_exists($class) || class_exists($class.'_Model'))
  48.  
  49. $obj = new $class();
  50.  
  51.  
  52. return $obj;
  53.  
  54. }
  55.  
  56. }
  57.  
  58. ?>

Gdy w polu PathImports dam sciezki czyli controllers,models etc to dziala jednak nie wiem jak zrobic zeby ladowalo je odrazu do tej tablicy i dzialalo mam nadzieje ze wiecie o co mi chodzi.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
marcio
post
Post #2





Grupa: Zarejestrowani
Postów: 2 291
Pomógł: 156
Dołączył: 23.09.2007
Skąd: ITALY-MILAN

Ostrzeżenie: (10%)
X----


Cytat
no a to do czego ? im dłuższy plik tym lepszy ?


Nie ze lepszy ale w tablicy wole miec sciezki a w stalych miec pelne sciezki do wszystkiego wtedy wystarczy zmienic tablice i sciezki sa ok i nie trzeba mieszac w stalych to raz a dwa to juz w reszcie aplikacji korzystam z takiego czegos:

  1.  
  2. $cfg = Loader::load('Cfg');
  3.  
  4. $def_cntrl = $cfg -> controller;
  5.  


Etc.. i jest mi tak wygodniej dawac tez sciezki tylko do importu plikow wole miec stale a na reszty config zmienne w tablicy ktore moge potem wykorzystac jako obiekt.



Rozwiazalem to tak:

config.php

  1.  
  2. <?php
  3.  
  4. /*
  5. ***********************************************
  6. |Sciezki do MVC libraries/plugins/components                       *
  7. ***********************************************
  8. */
  9.  
  10. $configs['PathControllers'] = 'controllers/';
  11.  
  12. $configs['PathModels'] = 'models/';
  13.  
  14. $configs['PathViews'] = 'views/';
  15.  
  16. $configs['PathLibs'] = 'libraries/';
  17.  
  18. $configs['PathPlugins'] = 'plugins/';
  19.  
  20. $configs['PathModules'] = 'components/';
  21.  
  22. $configs['PathConfig'] = 'config/';
  23.  
  24. //Inne ustawienia niepotrzebne do tego posta
  25.  
  26. /*
  27. ********************
  28. |Import plikow               *
  29. ********************
  30. */
  31.  
  32.  
  33. $dir_root = str_replace( "\\", "/", realpath( dirname(__FILE__) ) );
  34.  
  35. define('DIR_ROOT', $dir_root.'/');
  36. define('DIR_CTRL', DIR_ROOT.$configs['PathControllers']);
  37. define('DIR_MODELS', DIR_ROOT.$configs['PathModels']);
  38. define('DIR_VIEWS' , DIR_ROOT.$configs['PathViews']);
  39. define('DIR_PLUGINS_MODELS' , DIR_ROOT.$configs['PathPlugins'].$configs['PathModels']);
  40. define('DIR_PLUGINS_VIEWS' , DIR_ROOT.$configs['PathPlugins'].$configs['PathViews']);
  41. define('DIR_COMPONENTS_CTRL' , DIR_ROOT.$configs['PathModules'].$configs['PathControllers']);
  42. define('DIR_COMPONENTS_MODELS' , DIR_ROOT.$configs['PathModules'].$configs['PathModels']);
  43. define('DIR_COMPONENTS_VIEWS' , DIR_ROOT.$configs['PathModules'].$configs['PathViews']);
  44. define('DIR_LIBRARY' , DIR_ROOT.$configs['PathLibs']);
  45. define('DIR_CONFIG' , DIR_ROOT.$configs['PathConfig'])
  46.  
  47. $configs['path'] = array(
  48.  
  49. DIR_CTRL,
  50. DIR_MODELS,
  51. DIR_VIEWS,
  52. DIR_PLUGINS_MODELS,
  53. DIR_PLUGINS_VIEWS,
  54. DIR_COMPONENTS_CTRL,
  55. DIR_COMPONENTS_MODELS,
  56. DIR_COMPONENTS_VIEWS,
  57. DIR_LIBRARY,
  58. DIR_CONFIG
  59.  
  60. );
  61.  
  62.  
  63.  
  64.  
  65. return $configs;
  66. ?>
  67.  
  68.  


Import.php

  1.  
  2. <?php
  3.  
  4. require_once('libraries/Loader.php');
  5.  
  6. class Imports {
  7.  
  8.  
  9. private $cfg;
  10.  
  11.  
  12. public function __get($class) {
  13.  
  14.  
  15. $this -> cfg = Loader::load('Cfg');
  16.  
  17. foreach($this -> cfg -> path as $key => $imports) {
  18.  
  19. if(file_exists($imports.$class.'.php')) {
  20.  
  21. require_once($imports.$class.'.php');
  22.  
  23. }
  24.  
  25. else if(file_exists($imports.$class.'_Model.php')) {
  26.  
  27. require_once($imports.$class.'_Model.php');
  28.  
  29. }
  30.  
  31. }
  32.  
  33. if(class_exists($class) || class_exists($class.'_Model'))
  34.  
  35. $obj = new $class();
  36.  
  37.  
  38. return $obj;
  39.  
  40. }
  41.  
  42. }
  43.  
  44. ?>
  45.  
  46.  


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: 13.10.2025 - 14:55