में आंशिक उपयोग करने के लिए ZF1 में हम ऐसे ही layout.phtml फ़ाइल कुछ में आंशिक उपयोग करनेकैसे zendframework2
$this->partial('header.phtml', array('vr' => 'zf2'));
हम ZF2 में एक ही कैसे कर सकते?
में आंशिक उपयोग करने के लिए ZF1 में हम ऐसे ही layout.phtml फ़ाइल कुछ में आंशिक उपयोग करनेकैसे 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
के आधार पर एक रिश्तेदार पथ का उपयोग कर सकते हैं।
मान लीजिए आप परिभाषित:
'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',
),
),
);
अपने module.config.php में
और अपने listsnippet.phtml .../view/mycontroller/snippets/listsnippet.phtml
में निहित है, तो आप निम्नलिखित कोड का उपयोग कर सकते हैं:
echo $this->partial('mycontroller/snippets/listsnippet.phtml', array('key' => 'value'));
सभी दृश्य चर पास करने के लिए आंशिक: 'इस $ echo e-> आंशिक (' लेआउट/हेडर ', $ यह-> देखें मॉडल() -> getCurrent() -> getVariables()); ' – davmor
ध्यान दें कि' $ this-> viewModel() -> getCurrent() -> getVariables() 'एक [ArrayObject] देता है (http://php.net/manual/en/class.arrayobject.php)। – davmor
अतिरिक्त डेटा को मर्ज करने के लिए, array_merge काम करता है: $ echo-> आंशिक ('mypartial', array_merge ($ this-> viewModel() -> getCurrent() -> getVariables(), [moredata])); – Killan