I did not get the extract () function and passed the variables. I have a method in the user controller where certain variables are defined and sent to the array of the view function in the parent controller where the array is retrieved. Then a presentation is required. But the variables are undefined. The contents of the array can be printed.
Here is a user controller with a simplified profile function:
class User extends Controller{ public function profile(){ $profiledetails = $this->profiledetails(); $profilestatus = $this->profileStatus(); $this->view('profile', [$profiledetails, $profilestatus]); }}
Variables are sent to the view function in the parent controller:
class Controller { public function view($view, $variables =[]){ extract($variables); require_once './app/views/' . $view . '.php'; }}
And in the view "profile.php" the error of the variable undefined is displayed. I thought the "extract ()" function would make $ profiledetails and $ profilestatus available as variables in the view. What am I doing wrong? Maybe I'm using the wrong array type, or should I use variable variables or something like that (in this case, how?).
source share