mam problem z przekazaniem referencji obiektu. A mianowicie:
Klasa View:
class View { private $mConfig = null; private $mSmarty = null; /* konstruktor */ public function __construct($pConfig) { /* ładowanie biblioteki */ require_once('system/smarty/Smarty.class.php'); $this->mConfig = $pConfig; $this->mSmarty = new Smarty(); /* konfiguracja */ $this->mSmarty->setTemplateDir('/application/views/'); $this->mSmarty->setCompileDir('/application/smarty/compile/'); $this->mSmarty->setConfigDir('/application/smarty/config/'); $this->mSmarty->setCacheDir('/application/smarty/cache/'); $this->mSmarty->debugging = $this->mConfig->get('debugging'); $this->mSmarty->caching = $this->mConfig->get('caching'); $this->mSmarty->cache_lifetime = $this->mConfig->get('cache_lifetime'); } /* podstawianie wartości do klucza */ public function assign($pKay, $pValue){ $this->mSmarty->assign($pKey, $pValue); } /* wyświtlanie widoku */ public function display($pTemplateFile){ $this->mSmarty->display('application/view/'.$pTemplateFile); } }
Klasa Controller:
abstract class Controller { private $mView = null; public function setView($pView){ $this->mView = $pView; } public function getView(){ return $this->mView; } }
Klasa Index:
class Index extends Controller { public function index(){ $this->getView()->assign('name', 'value'); } }
I teraz wywołanie:
include_once('system/core/Config.php'); include_once('system/core/View.php'); $config = new Config(); $view = new View($config); $index = new Index(); $index->setView($view); $index->index();
Otrzymuje błąd: Fatal error: Call to a member function assign() on a non-object in D:\EasyPHP-12.1\www\falcon\application\controller\index.php on line 12
Czyli zmienna jest nie jest obiektem ?
Ta linia to: $this->getView()->assign('name', 'value');
Jeżeli użyje funkcji var_dump to wyświetla się NULL, a następnie info o obiekcie jakby istniał :/
Pierwszy raz pisze w PHP obiektowo zazwyczaj piszę w JAVA i C# więc może coś robię tak ?
Poproszę o jakieś rady
