2012-06-05 8 views
11

मैं एक मॉड्यूल के अंदर अपने निर्देशिका संरचना के लिए कुछ इस तरह है:ज़ेंड फ्रेमवर्क 2 मॉड्यूल के अंदर आंशिक रूप से कैसे प्रस्तुत करता है?

Api 
├── Module.php 
├── config 
│   └── module.config.php 
├── src 
│   └── (..etc ..) 
└── view 
    ├── api 
    │   └── api 
    │    └── index.phtml 
    └── partial 
        └── test.phtml 

फिर, मैं यह कर रहा हूँ:

<?= $this->partial('partial/test.pthml', array()); ?> 

हालांकि, मैं मिलता है:

05-Jun-2012 14:56:58] PHP Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "partial/test.pthml"; resolver could not resolve to a file' in /Users/jeff/web/n/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:463

कहां मेरे आंशिक जाना चाहिए?

+1

आपका निर्देशिका संरचना की तरह सही है और अपनी आंशिक दृश्य सहायक सही ढंग से स्थापित किया जाएगा। बस सुनिश्चित करें कि आपके पास '' template_path_stack '=> array (' user '=> __DIR__।' /../ view ') है,' आपके 'module.config.php' फ़ाइल में जोड़ा गया है और आपको अच्छा होना चाहिए। –

उत्तर

21

इस से

echo $this->partial('layout/header', array('vr' => 'zf2')); 

प्राप्त किया जा सकता आप

echo $this->vr; 
का उपयोग कर दृश्य में चर का उपयोग कर सकते

निम्नलिखित अपने view_manager में पंक्ति जोड़ने के लिए भूल नहीं है module.config.php फ़ाइल का।

'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', 
     ), 


    ),  

); 
+0

मेरे मॉड्यूल में, मैं निम्न का उपयोग करता हूं: $ this-> आंशिक ('{मॉड्यूल}/{नियंत्रक}/{filename} .phtml', सरणी ('var_name_in_partial' => $ डेटा)); –

+0

इच्छा है कि मैं दो बार मतदान कर सकता हूं। वास्तव में अच्छी व्याख्या। –

संबंधित मुद्दे