Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Problem z przekazaniem argumentu funkcji
tomi1985
post
Post #1





Grupa: Zarejestrowani
Postów: 192
Pomógł: 12
Dołączył: 23.09.2010
Skąd: Warszawa

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


Witam,
jestem dopiero raczkujący z php obiektowo także prosiłbym o pomoc....

a mianowicie, mam dwa pliku

config.php
Kod
class Config{
  
    public function changeSite(){
        $siteName = 'test';
        echo 'mam siteName: --'.$siteName.'--<br/>';
        return $siteName;
    }
}


i plik Index

Kod
include_once 'class/Tables.php';
include_once 'class/TopAds.php';
include_once 'config/config.php';
include_once 'libs/Smarty.class.php';

class Enoclegi {
    private $smarty;
    private $topAds;
    private $tables;
    private $config;
    
    //constructor
    public function Enoclegi() {
        $this->smarty     =    new Smarty();
        $this->config    =    new Config();
        $this->topAds    =    new TopAds();
        $this->tables    =    new Tables();
    }
    
    public function init(){
        //$this->topAds    ->        lastAdd();        
        $this->config     ->              changeSite($siteName);
        $this->smarty    ->        assign('VoivodeshipShow', $this->tables->getVoivodeship());
        $this->smarty    ->        assign('CategoryShow', $this->tables->getCategory());
        $this->smarty    ->        display('tpl/index.tpl');
    }
}



jak sprawić aby zmienna $siteName z configu została przekazana do
Kod
$this->config     ->      changeSite($siteName);
Go to the top of the page
+Quote Post
--Konki--
post
Post #2





Goście







Przecież tu jest wszystko źle. Nie rozumiem jak to by miało działać ;-)
Go to the top of the page
+Quote Post
--Konki--
post
Post #3





Goście







Spróbuj tak:
  1. class Config{
  2. public function changeSite($siteName){
  3. //$siteName = 'test';
  4. echo 'mam siteName: --'.$siteName.'--<br/>';
  5. return $siteName;
  6. }
  7. }


wywołanie
  1. include_once 'class/Tables.php';
  2. include_once 'class/TopAds.php';
  3. include_once 'config/config.php';
  4. include_once 'libs/Smarty.class.php';
  5.  
  6. class Enoclegi {
  7. private $smarty;
  8. private $topAds;
  9. private $tables;
  10. private $config;
  11.  
  12. //constructor
  13. public function Enoclegi() {
  14. $this->smarty = new Smarty();
  15. $this->config = new Config();
  16. $this->topAds = new TopAds();
  17. $this->tables = new Tables();
  18. }
  19.  
  20. public function init(){
  21. //$this->topAds -> lastAdd();
  22. $this->config -> changeSite($_SERVER['REQUEST_URI']);
  23. $this->smarty -> assign('VoivodeshipShow', $this->tables->getVoivodeship());
  24. $this->smarty -> assign('CategoryShow', $this->tables->getCategory());
  25. $this->smarty -> display('tpl/index.tpl');
  26. }
  27. }


Pisane na klolanie i nie testowane.

Podstawowe błędy:
1. W wywołaniu które miałeś ($this->config -> changeSite($siteName)wink.gif jest $siteName które nigdzie nie jest zdefiniowane
2. Funkcja changeSite nie ma parametru a wywołujesz z parametrem

Pozdrawiam,
Konki
Go to the top of the page
+Quote Post

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: 20.08.2025 - 10:45