【问题标题】:Passing Form to Template using RenderWith method使用 RenderWith 方法将表单传递给模板
【发布时间】:2012-12-04 18:02:52
【问题描述】:

我正在使用 Willr 的 Silverstripe cmets 模块以及作为页面的 DataObjects 实现。

cmets 模块允许您将 cmets 附加到数据对象 - 我已经这样做了。我遇到的问题是,当我尝试使用 renderwith 将自定义字段从 Datobject 传递到模板时,传递的 CommentsForm 会呈现表单,但不会将通过传递的表单创建的任何 cmets 与 DataObject 关联。

这是我的 PostsPageHolder 上的操作和 renderWith 方法:

    public function view($request) {
    $segment = $request->param('ID');

    if ($obj = Post::get()->filter('URLSegment', $segment)->First()) :
        switch ($obj->Type) {
            case 'News-Post' :
                return $this->renderWith(
                    array('PostsPage_view_news', 'Page'),
                    array(
                        'Object'        => $obj,
                        'Type'          => $obj->Type,
                        'Title'         => $obj->Title,
                        'Entry'         => $obj->Entry,
                        'CommentsForm'  => $obj->CommentsForm
                    )
                );
                break;
    ...
}

有谁知道我如何使用 RenderWith() 数组通过表单?

【问题讨论】:

  • 想通了 - 你需要传递 'CommentsForm' => $obj->CommentsForm()

标签: silverstripe


【解决方案1】:

试试customise(array),这里显示https://docs.silverstripe.org/en/3/tutorials/site_search/#showing-the-results

return $this->customise(array(
    'Object'        => $obj,
    'Type'          => $obj->Type,
    'Title'         => $obj->Title,
    'Entry'         => $obj->Entry,
    'CommentsForm'  => $obj->CommentsForm
))->renderWith(
    array('PostsPage_view_news', 'Page')
);

【讨论】:

    猜你喜欢
    • 2017-03-02
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 2019-08-30
    • 1970-01-01
    • 2014-07-17
    • 1970-01-01
    相关资源
    最近更新 更多