Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用extract($variables)获取内容,但变量未定义_Php_Arrays_Variables_Model View Controller_Extract - Fatal编程技术网

Php 使用extract($variables)获取内容,但变量未定义

Php 使用extract($variables)获取内容,但变量未定义,php,arrays,variables,model-view-controller,extract,Php,Arrays,Variables,Model View Controller,Extract,我还没有掌握extract()函数的诀窍,以及如何传输变量。 我在用户控制器中有一个方法,其中定义了一些变量,并以数组的形式发送给父控制器中的视图函数,在父控制器中提取数组。那么视图是必需的。但是这些变量没有定义。但是可以打印数组内容 以下是具有简化配置文件功能的用户控制器: class User extends Controller{ public function profile(){ $profiledetails = $this->profiledet

我还没有掌握extract()函数的诀窍,以及如何传输变量。 我在用户控制器中有一个方法,其中定义了一些变量,并以数组的形式发送给父控制器中的视图函数,在父控制器中提取数组。那么视图是必需的。但是这些变量没有定义。但是可以打印数组内容

以下是具有简化配置文件功能的用户控制器:

class User extends Controller{

    public function profile(){

         $profiledetails = $this->profiledetails();           
         $profilestatus = $this->profileStatus();            

         $this->view('profile', [$profiledetails, $profilestatus]);
}}    
变量被发送到父控制器中的view函数:

class Controller {
    public function view($view, $variables =[]){                    

    extract($variables);

    require_once './app/views/' . $view . '.php';
}}
在“profile.php”视图中,显示了未定义的变量错误。我认为“extract()”函数将使$profiledetails和$profilestatus作为变量在视图中可用。
我做错了什么?也许我使用了错误的数组类型,或者我应该使用“variabe variables”之类的。。(在这种情况下,如何?。

提取
与关联数组一起使用

    $this->view('profile', 
      [
        'profiledetails' => $profiledetails, 
        'profilestatus' => $profilestatus
      ]);   

extract
需要一个关联数组。根据文档,它需要:非常棒。谢谢