Symfony:是否可以为组件设置模板? [英] Symfony: Is it possible to setTemplate for components?

查看:31
本文介绍了Symfony:是否可以为组件设置模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

组件没有 setTemplate()!我知道,但也许还有其他方法可以做到?

There’s no setTemplate() for components! I know but maybe there is another way to do it ?

(问题似乎与 php 框架有关:http://www.symfony-project.org/)

(The question seems to be about a php framework: http://www.symfony-project.org/)

推荐答案

sfComponents 上没有 setTemplate 方法.您基本上有 3 个选择:

There is no setTemplate method on sfComponents. You essentially have 3 options:

  1. 将您的组件命名为您希望组件呈现的部分名称.如果您有多个组件想要共享同一个模板,这可能是不可能的.
  2. 创建一个与您的组件同名的部分,并在那里包含该部分.也就是说,如果您有一个带有 executeFoo() 方法的组件想要呈现 _bar.php 模板,只需调用 include_partial('bar',$vars)_foo.php 中.
  3. 加载 PartialHelper 并在组件 execute 方法内手动渲染部分,并让组件返回 sfView::NONE.
  1. Name your component the same as the partial you'd like the component to render. This may not be possible if you have multiple components you'd like to share the same template.
  2. Create a partial with the same name of your component and include the partial there. That is, if you had a component with an executeFoo() method that you wanted to render the _bar.php template, simply call include_partial('bar', $vars) inside of _foo.php.
  3. Load the PartialHelper and render the partial manually inside of the components execute method and have the component return sfView::NONE.

这篇关于Symfony:是否可以为组件设置模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆