在 Symfony 1.4 中渲染任务的部分内容
我正在尝试在 Symfony 任务中渲染部分内容,但没有运气。我在 1.1 中发现文档说只需调用 get_partial() ,但显然在 1.4 中不再可用。我尝试使用 sfLoader::getHelpers('Partial'); 手动加载帮助程序,但我收到“Class sfLoader not found”。任何帮助将不胜感激。
作为参考,我想做的是从我的所有布局中使用的全局标头部分生成一个名为“header.html”的 HTML 文件,以便包含在我正在集成的第三方论坛(Simple Machines/SMF)中。
I'm trying to render a partial in a Symfony task and having no luck. I found docs in 1.1 that say to just call get_partial()
but apparently that's no longer readily available in 1.4. I tried loading the helper manually with sfLoader::getHelpers('Partial');
but I get "Class sfLoader not found". Any help would be greatly appreciated.
For reference what I'm trying to do is generate an HTML file called 'header.html' from my global header partial used in all of my layouts for inclusion in a third-party forum I'm integrating (Simple Machines/SMF).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
第一次加载:
然后调用:
First load:
then just call:
不要忘记在任务选项中添加应用程序名称。查找这一行:
现在
$this->configuration
返回您需要的sfApplicationConfiguration
。Don't forget to add an application name in your task's options. Look for this line:
Now
$this->configuration
returns thesfApplicationConfiguration
that you need.这就能解决问题:
This will do the trick:
sfLoader
在 symfony 1.2 中已弃用 - 我认为您需要查看 1.4 API 以及您熟悉的任何版本的升级帮助,因为这些将是您需要参考的资源到很多。解决问题的技巧是使用
sfApplicationConfiguration
类提供的loadHelpers()
方法加载帮助器 - 您的任务应该在其configure( )
方法。我自己以前没做过,请注意...sfLoader
was deprecated in symfony 1.2 - I think you need to look over the 1.4 API and the upgrade help from whichever version you're familiar with, as these are going to be resources you'll need to refer to a lot.The trick to solving your problem is to load the helper with the
loadHelpers()
method provided by thesfApplicationConfiguration
class - your task should hook this method in itsconfigure()
method. I've not done it before myself, mind...刚刚在任务中调用了部分用于发送免费试用 nag 电子邮件的代码:
Just called a partial in a task for use in sending free trial nag email here's the code:
您可以使用您还可以在taskClass::configure()方法中定义应用程序命令选项来访问当前配置
(如果您已使用symfony生成:任务来生成任务类,您应该将前端作为默认应用程序选项)。
或者,您可以在调用任务时使用 --application=appName 从 cli 传递应用程序。
you can access the current configuration with
You can also define application command option in taskClass::configure() method (if you have used the symfony generate:task to generate the task class you should have frontend as default application option).
Optionally you can pass an application using --application=appName from cli when calling your task.
确保在您的配置方法中具有应用程序选项:
然后,在执行方法中:
这样您就可以防止这些错误:
和
Be sure to have the application option in your configure method:
And then, in the execute method:
On this way you will prevent these errors:
and