0

我有以下代码返回带有子视图的视图。正如它所看到的,子视图重复了变量 $form 和数组 &fields 将变量的传递复制到视图中。

如何从 responseView 继承 userProfileInformationView 这些变量并将它们仅注入 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;
4

1 回答 1

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;
    ?>
于 2013-05-10T19:35:41.167 回答