2012-11-15 63 views
0

我想分離我的內容和視圖(而不是反高潮,我知道)。我想要的就像gettext,我可以在視圖中有一個鍵。像Content_Materials_Index_Description之類的東西,然後使用類似echo "@Content_Materials_Index_Description"的東西,以呈現我已經存儲在一個單獨的文件中的3-4段內容。在Zend Framework中外部化內容

我知道如何在Java/J2EE應用程序甚至VB.net中做到這一點,並希望使用Zend Framework來做到這一點。

說明:

觀點:

<div id="wrapper"> 
    <a href="/Home">HomePage</a> 
    <div id="content"><?echo "@content_materials_index_Description"?></div> 
</div> 

messageResource.ini文件

content_materials_index_Description=Materials for production can be edited here. Click on the name of a material to edit it. The cross sign... 
+0

你並不清楚。你的問題到底是什麼?你有什麼嘗試?顯示一些代碼,你是如何失敗的? – markus

+0

什麼是反對分離內容和觀點的climaCtic? – markus

+0

我發現的是翻譯,但它更像是獲取整個文本塊。 –

回答

1

您可以使用諧音爲這一點,你可以通過一些參數,它呈現的內容例如表格,列表等

查看文件

$this->partial('path-to-partial/partial-name.phtml', array(
    'var1'=>$myVar1, 
    'var2' => $myVar2 
)); 

部分文件

$this->myVar1; 
$this->myVar2; 

除此之外,你可以使用View helpers

0

其簡單,

在IndexController.php

public function indexAction() 
{ 
    //here you need to read the values from *.ini file. for ex. with Zend_Config_Ini 
    $this->view->content_materials_index_Description = 'text for description....'; 
} 

在查看index.phtml

<div><?php echo $this->content_materials_index_Description; ?></div>