2013-05-09 89 views
0

我有以下代码返回一个视图与子视图。 可以看到,子视图重复变量$ form和数组&复制变量传递到视图中。Zend Framework 2 inherid变量从父视图

我如何继承userProfileInformationView这些变量从responseView中注入并只注入到responseView中?

$responseView = new ViewModel(); 
    $responseView->setVariables(array(
     'form' => $form, 
     'fields' => $fields, 
     'userType' => $userType,     
    )); 
    $responseView->setTemplate('templates/logged_user_profile'); 
    $responseView->setTerminal(true); 
    $userProfileInformationView = new ViewModel(); 
    $userProfileInformationView->setTemplate('templates/logged_user_profile_information'); 
    $userProfileInformationView->setVariables(array(
     'form' => $form, //I don't want this 
     'fields' => $fields, //I don't want this 
    )); 
    $responseView->addChild($userProfileInformationView, 'userProfileInformation');  
    return $responseView; 

回答

2

我知道只有一个这样的代码:

<?php 
    $responseView = new ViewModel(); 
    $responseView->setVariables(array(
     'form' => $form, 
     'fields' => $fields, 
     'userType' => $userType,     
    )); 
    $responseView->setTemplate('templates/logged_user_profile'); 
    $responseView->setTerminal(true); 
    $userProfileInformationView = new ViewModel(); 
    $userProfileInformationView->setTemplate('templates/logged_user_profile_information'); 

    $userProfileInformationView->setVariables($responseView->getVariables()); 

    $responseView->addChild($userProfileInformationView, 'userProfileInformation');  
    return $responseView; 
    ?>