I’m create a model view controller framework and im kind of new to this. I want to pass variables from controllers to views. My View.php constructor looks like this:
function __construct($file, $args) {
$this->view = $file;
foreach($args as $key => $arg) {
$this->view->$key = 'awda';
}
}
it gives me error cause
$this->view->$key is not a valid statement.
If i do it from Controller something like
$this->view->hello = 'hello world'
and i do echo
$this->hello
in view it works fine, but i want to be able to have multiple vars passed in. Does anyone know a better way of doing this? thank you
You are attempting to assign properties to what I suspect is a string (
$file). Since you are inside your view’s constructor, you can simply use$thisto refer to the view: