의 부분을 사용하는어떻게 그런 layout.phtml 파일 무언가의 부분적인 사용 ZF1에서 zendframework2
$this->partial('header.phtml', array('vr' => 'zf2'));
우리가 ZF2에서 동일한 작업을 수행 할 수 있습니까?
의 부분을 사용하는어떻게 그런 layout.phtml 파일 무언가의 부분적인 사용 ZF1에서 zendframework2
$this->partial('header.phtml', array('vr' => 'zf2'));
우리가 ZF2에서 동일한 작업을 수행 할 수 있습니까?
이 사용보기에서 변수에 액세스 할 수 있습니다
echo $this->partial('layout/header', array('vr' => 'zf2'));
에 의해 달성 될 수있다
echo $this->vr;
이 module.config.php 파일의 당신의 view_manager에 다음 줄을 추가하는 것을 잊지 마세요.
'layout/header' => __DIR__ . '/../view/layout/header.phtml',
추가 한 후 이미 허용 대답에 명시된이
return array(
'view_manager' => array(
'template_path_stack' => array(
'user' => __DIR__ . '/../view' ,
),
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'layout/header' => __DIR__ . '/../view/layout/header.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
),
);
으로, 당신은
echo $this->partial('layout/header', array('vr' => 'zf2'));
을 사용할 수있는 것 같습니다 그러나 당신은 당신의 module.config에 layout/header
을 정의해야 .php. 당신이 당신의 template_map
을 복잡하게하지 않으려면
, 당신은 직접 부분을 가리 키도록 template_path_stack
을 기준으로 상대 경로를 사용할 수 있습니다. 당신의 module.config.php에서
'view_manager' => array(
/* [...] */
'template_path_stack' => array(
'user' => __DIR__ . '/../view' ,
),
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
),
);
하고 listsnippet.phtml 그런 다음 다음과 같은 코드를 사용할 수 있습니다, .../view/mycontroller/snippets/listsnippet.phtml
에있다 :
echo $this->partial('mycontroller/snippets/listsnippet.phtml', array('key' => 'value'));
모두보기 변수를 전달하려면 – davmor
'$ this-> viewModel()은 부분적으로 : '$ this-> viewModel() -> getCurrent() -> getVariables() -> getCurrent() -> getVariables()는 [ArrayObject]를 반환합니다 (http://php.net/manual/en/class.arrayobject.php). – davmor
추가 데이터를 병합하려면 array_merge가 작동합니다. echo $ this-> partial ('mypartial', array_merge ($ this-> viewModel() -> getCurrent() -> getVariables(), [moredata])); – Killan