0

这是 zf2 在从另一个控制器扩展的控制器之间共享视图的最正确方法。假设必须控制 A 和 B。A 扩展 B:

class AController extends BController{

}

class BController{
 public action shareAction(){
 }
}

1方式,在module config中将action share的view path指向B share view;

'template_map' => array(
    'a/index/index'   => __DIR__ . '/../view/a/index.phtml',
    'a/share/index'     => __DIR__ . '../../../../view/b/share/share.phtml',//SCALE TO REACH B VIEW

2方式,在模块配置中将动作共享的视图路径指向本地视图路径

'template_map' => array(
    'a/index/index'   => __DIR__ . '/../view/a/index.phtml',
    'a/share/index'     => __DIR__ . '../view/a/share/share.phtml',

在 put 的 share.phtml 中:

echo $this->partial('b/share/index')

或者如果有另一种最好的方法,哪个?

4

1 回答 1

2

You can change the template on an action by action basis too:

public function testAction()
{
    // If you wanted to change the actual base layout template:
    //$this->layout()->setTemplate('my/layout/base-layout.phtml');

    $viewModel = new ViewModel();
    $viewModel->setTemplate('my/template/here');

    return $viewModel;
}

The method you chose would depend how/why you want to do this, and if there's a pattern to the override or weather it's more of an adhoc basis. Above if fine if you are just planning to change the template in an adhoc manner

于 2013-07-04T11:09:59.803 回答