Passer des variables a la vue
Bonjours,
J'essaye de faire passer de simple variable a la vue mais cela ne semble pas marcher voici mon code sur un systeme MVC.
index.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
<?php
include '../application/configs/application.php';
include '../application/helpers/include.php';
include '../application/helpers/html.php';
include LIBRARY_PATCH . 'controllers.php';
include LIBRARY_PATCH . 'models.php';
if (file_exists(CONTROLLERS_PATCH . $getController . '.php'))
{
include CONTROLLERS_PATCH . $getController . '.php';
$controller = new $getController;
if(method_exists($getController, $getAction))
{
$controller->$getAction();
} else {exit('error action non defini');}
} else {exit('le controller n\'existe pas !');} |
controllers/index.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
<?php
class Index extends controllers{
public function index()
{
$d= array();
$d['tuto'] = array('test' => 'test');
$this->set($d); #tentative de faire passer $d a la vue
$this->loadModel('IndexModel');
$plop = 'plop';
$this->renders('index');
}
} |
views/index/index.php
Code:
1 2
|
<?php var_dump($thisd);?> #return NULL |
La controller lui meme controller.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
<?php
class controllers {
var $vars = array();
private $layout = LAYOUT_NAME;
public function set($d) {
$this->vars = array_merge($this->vars, $d);
}
public function renders($file)
{
extract($this->vars);
ob_start();
require VIEWS_PATCH . get_class($this) . '/' . $file . '.php';
$content = ob_get_clean();
if ($this->layout == false)
{
echo $content;
}else {
require LAYOUTS_PATCH . '/' . $this->layout . '.php';
}
//include LAYOUTS_PATCH . '/' . $this->layout . '.php';
}
public function loadModel($name) {
include MODELS_PATCH . $name . '.php';
$this->$name = new $name();
}
}
?> |
Si quequ'un de gentil voudrai m'expliquer.. parce que la je ne comprends ou est le bug.
Merci