php - Getting contents with extract($variables), but the variables are undefined -
i haven't gotten hang of extract() function, , transferring variables. have method in user controller variables defined, , sent in array view function in parent controller, array extracted. view required. variables turn out undefined. array contents can printed though.
here user controller simplified profile function:
class user extends controller{ public function profile(){ $profiledetails = $this->profiledetails(); $profilestatus = $this->profilestatus(); $this->view('profile', [$profiledetails, $profilestatus]); }} the variables sent view function in parent controller:
class controller { public function view($view, $variables =[]){ extract($variables); require_once './app/views/' . $view . '.php'; }} and in view, 'profile.php', undefined variable error shown. thought "extract()" function make $profiledetails , $profilestatus available variables in view. doing wrong? maybe i'm using wrong type of array, or should use "variabe variables" or something.. (in case, how?).
extract works associative array.
$this->view('profile', [ 'profiledetails' => $profiledetails, 'profilestatus' => $profilestatus ]);
Comments
Post a Comment