I have a problem, Ive been making my own MVC app but there seems to be a problen in passing variables between model and controller. Output from controller is a single variable containing some json format data and it looks simple.
Controller
<?php
class controllerLib
{
function __construct()
{
$this->view = new view();
}
public function getModel($model)
{
$modelName = $model."Model";
$this->model=new $modelName();
}
}
class controller extends controllerLib
{
function __construct()
{
parent::__construct();
}
public function addresses($arg = false)
{
echo'Addresses '.$arg.'<br />';
$this->view->render('addressesView');
$this->view->showAddresses = $this->model->getAddresses();
}
}
?>
View
<?php
class view
{
function __construct()
{
}
public function render($plik)
{
$render = new $plik();
}
}
class addressesView extends view
{
public $showAddresses;
function __construct()
{
parent::__construct();
require 'view/head.php';
$result = $this->showAddresses;
require 'view/foot.php';
}
}
?>
Now problem is that $this->showAddresses does not pass to view and im stuck.
The code have various issues:
render() save the new View in a local var so that don’t exists after the function end
You can’t expect
$this->showAddressesto have a value at the constructor time.You should implement the render() method as a method outside of the View constructor.
View class:
addressesView class:
Controller class: