Beginnner question about PHP and MVC

xyleli8gas

New Member
I'm trying to learn MVC architecture for PHP. So I play with some simple classes and functions. I can't find what's wrong with this code, which returns a:
\[quote\] Fatal error: Call to a member function fetch() on a non-object in /opt/lampp/htdocs/test/MVC/Vue.php on line 15\[/quote\]Here's my code:Model.php:\[code\]class News { public function ConnBdd() { $this->bdd = new PDO('mysql:host=localhost;dbname=db301591273', 'root', ''); $this->query = "SELECT Nom,IdTest,Image,DATE_FORMAT(DateCreation, '%Y-%m-%d') AS DateCreation FROM Questionnaires WHERE autorise='1' ORDER BY DateCreation DESC LIMIT 0, 4"; $this->preparedQuery = $this->bdd->prepare($this->query); $this->executedQuery = $this->preparedQuery->execute(); } }\[/code\]Controller.php\[code\]class Controller { public $Model; public $View; public $News; public function ShowNews(){ $this->News->ConnBdd(); $this->View->ShowDaNews(); }}\[/code\]View.php\[code\]class View { public $Model; public $News; public function ShowDaNews() { while ($c = $this->News->executedQuery->fetch()) {?> <tr> <td class="tableImg"><?echo '<img src="http://stackoverflow.com/img/ico/'.$tests['Image'].'.png" />'?></td> <td class="tableTest"><?echo '<a href="http://stackoverflow.com/page/php?t='.$tests['IdTest'].'">'.$tests['Nom'].'</a>'?></td> </tr> <?} }}\[/code\]and Index.php\[code\]require_once 'Modele.php';require_once 'Controleur.php';require_once 'Vue.php';$Model= new Model();$Controller = new Controller();$View = new View();$Controller->Model = $Model;$Controller->View = $View;$News = new News();$Controller->News = $News;$View->News = $News;$Controller->ShowNews();\[/code\]Thanks for your help.
 
Back
Top