3
Hi, I made a mvc application but I’m having trouble passing a controller variable to the view. My codes:
class Home extends Controller {
public function index() {
$user = $this->loadModel('usersModel');
$row = $user->getUserData(Session::get('user_id'));
$this->loadView('_templates/header');
$this->loadView('home/index');
$this->loadView('_templates/footer');
}
}
View:
<?php echo $user; ?>
Transform
$user
in class attributeHome
and add a methodfunction getUser()
giving areturn $this->user
;– user28595
Then call the method in the view, after instantiating
Home
, with a simpleecho $HomeObj->getUser();
– user28595
could do that in my code? I just didn’t understand your logic
– user28062
loadView()
only makes a file include?– rray
@rray yes, a require (has $data = null in function parameters)
– user28062
raisin
$row
on the index,$this->loadView('home/index', $row);
– rray
Not clear enough. Is this a known framework? Do you have documentation? Or did you create the framework? Normally you should have some compiler for view templates. View helpers should usually have a variable signature method.. is by this method that you pass the controller/model data to the view.
– Daniel Omine
I created the framework, and there is no documentation.
– user28062