Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Klasa w klasie
mablo
post 5.12.2005, 00:26:38
Post #1





Grupa: Zarejestrowani
Postów: 120
Pomógł: 1
Dołączył: 11.04.2005
Skąd: Poznań

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


Odrazu mowie php 4.
Mam coś takiego
index.php:
  1. <?
  2. require("includes/initiate.php");
  3. /* Ładowanie modółów */
  4. include "pages/news.php";
  5. $news = new news();
  6. $news -> __construct();
  7. $news -> show();
  8. ?>

news.php:
  1. <?php
  2. class news
  3. {
  4.  
  5. var $limit;
  6.  
  7. function __construct()
  8. {
  9. $this -> limit = "10";
  10. }
  11.  
  12. function show ()
  13. {
  14.  
  15.  $db = new db();
  16. $db -> connect( DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASES);
  17. $Smarty = new Smarty();
  18. $Smarty -> template_dir = 'templates/';
  19. $Smarty -> compile_dir = 'templates_c/';
  20.  
  21. $s_SN = $db -> query ( "SELECT * FROM NEWS LIMIT ".$this -> limit.";" );
  22.  
  23. $newsy = array ();
  24. while ($row = $db -> fetch_assoc ($s_SN))
  25. $newsy[] = $row; 
  26.  
  27. $Smarty -> assign("news", $newsy);
  28. $Smarty -> display('news.tpl');
  29. }
  30. }
  31. ?>

initiate.php:
  1. <?php
  2. require( "libs/db.class.php" );
  3. require( "libs/Smarty.class.php" );
  4. require( "config.php" );
  5.  
  6. $db = new db();
  7. $db -> connect( DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASES);
  8.  
  9. $Smarty = new Smarty();
  10. $Smarty -> template_dir = 'templates/';
  11. $Smarty -> compile_dir = 'templates_c/';
  12. ?>


Czy moge jakoś ominąc odpalanie klas db i smarty w funkcji show (news.php) questionmark.gif Żeby odpalały się w pliku initiate.php bo dodawanie odpalania klas smarty i db za każdym razem jest troche uciążliwe.
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 Wersja Lo-Fi Aktualny czas: 19.07.2025 - 18:45