首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Zend Framework中外部化内容

在Zend Framework中外部化内容
EN

Stack Overflow用户
提问于 2012-11-16 00:08:58
回答 2查看 39关注 0票数 0

我想把我的内容和观点分开(我知道,这是一种反高潮的做法)。我想要的是像gettext这样的东西,我可以在视图中拥有一个键。像Content_Materials_Index_Description,然后使用像echo "@Content_Materials_Index_Description"这样的东西来渲染3-4段内容,我已经存储在一个单独的文件中。

我知道如何在Java/J2EE应用程序甚至是VB.net中做到这一点,并希望得到使用Zend Framework来做到这一点的建议。

解释:

查看:

代码语言:javascript
复制
 <div id="wrapper"> 
  <a href="/Home">HomePage</a>
  <div id="content"><?echo "@content_materials_index_Description"?></div>
 </div>

messageResource.ini文件

代码语言:javascript
复制
content_materials_index_Description=Materials for production can be edited here. Click on the name of a material to edit it. The cross sign...
EN

回答 2

Stack Overflow用户

发布于 2012-11-16 00:11:34

你可以使用partials,你可以传递一些参数给它来呈现内容,比如Table,List等等。

查看文件

代码语言:javascript
复制
$this->partial('path-to-partial/partial-name.phtml', array(
    'var1'=>$myVar1, 
    'var2' => $myVar2
));

部分文件

代码语言:javascript
复制
$this->myVar1;
$this->myVar2;

除此之外,您还可以使用View helpers

票数 1
EN

Stack Overflow用户

发布于 2012-11-16 00:42:49

它很简单,

在IndexController.php中

代码语言:javascript
复制
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中

代码语言:javascript
复制
<div><?php echo $this->content_materials_index_Description; ?></div>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13401536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档