Hi there,
I’m looking to find a good way to moev data between middleware, container and views (PHP-View).
For example, site has a form that changes language, $_POST is read on middleware and I would need this language variable also on container and views. Is it a bad practise to just be ugly and do something like:
// middleware
// handle and verify $_POST[‘language’] and then…
$this->language = $language;
// container
$view->language = $c->language;
// view
// access selected language
echo $this->language;
Or what’s the recommended way to do something like this?
Thanks. So if I need to access current language in template, i.e. form select where current language needs to be selected, I just use session variable inside view file or should it be injected in the view object?
Is it commonly bad practise to create variables or arrays or whatever custom stuff inside app object (like $app->myVar = ‘whatever’)?
Yes this is generally considered bad practice… you really want to look passing these things around using Dependency injection and not service location.