0

I have the following code which returns a view with a subview. As it can see, the subview repeats the variable $form and the array &fields duplicating the pass of variables into view.

How I can inherit to userProfileInformationView these variables from responseView and inject them only into 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;
tereško
  • 58,060
  • 25
  • 98
  • 150
josepmra
  • 617
  • 9
  • 25

1 Answers1

2

I know only one way to code this:

    <?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;
    ?>
Remi Thomas
  • 1,528
  • 1
  • 15
  • 25