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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -