kısmi kullanmaknasıl böyle layout.phtml dosya şey kısmi kullanmak ZF1 olarak zendframework2
$this->partial('header.phtml', array('vr' => 'zf2'));
biz ZF2 aynı nasıl yapabilirim?
kısmi kullanmaknasıl böyle layout.phtml dosya şey kısmi kullanmak ZF1 olarak zendframework2
$this->partial('header.phtml', array('vr' => 'zf2'));
biz ZF2 aynı nasıl yapabilirim?
Bu kullandığınız görünümde değişkeni erişebilir
echo $this->partial('layout/header', array('vr' => 'zf2'));
sağlanabilir
echo $this->vr;
module.config.php dosyanızın view_manager aşağıdaki satırı ekleyin unutmayın.
'layout/header' => __DIR__ . '/../view/layout/header.phtml',
ekledikten sonra, önceden kabul cevap belirtilen bu
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',
),
),
);
olarak,
echo $this->partial('layout/header', array('vr' => 'zf2'));
kullanabilirsiniz gibi görünüyor ama o zaman module.config içinde layout/header
tanımlamak zorunda .php. Eğer senin template_map
kalabalıklaştırmasını istemiyorsanız
, doğrudan kısmi işaret edecek template_path_stack
dayalı göreli bir yol kullanabilirsiniz. senin module.config.php içinde
'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',
),
),
);
ve listsnippet.phtml sonra aşağıdaki kodu kullanabilirsiniz, .../view/mycontroller/snippets/listsnippet.phtml
yatıyor:
echo $this->partial('mycontroller/snippets/listsnippet.phtml', array('key' => 'value'));
tüm görünüm değişkenleri geçmek için kısmi olarak: 'echo $ this-> kısmi ('layout/header', $ this-> viewModel() -> getCurrent() -> getVariables());' – davmor
Not: Bu this-> viewModel() -> getCurrent() -> getVariables() 'bir [ArrayObject] döndürür (http://php.net/manual/en/class.arrayobject.php). – davmor
Ek verileri birleştirmek için array_merge çalışır: echo $ this-> partial ('mypartial', array_merge ($ this-> viewModel() -> getCurrent() -> getVariables(), [moredata])); – Killan