我应该在模型或控制器中初始化 DOMdocument

Should I initialize DOMdocument in the model or controller

我最近构建了一个脚本,该脚本使用 DOMdocument 从 CMS 生成 XML 帖子提要。我可以正常工作,但我想将其进一步集成为 MVC 应用程序。

作为基本结构,我使用 PIP。我喜欢它的简明扼要,它应该能让我轻松地按照我希望的方式实现我的应用程序。

问题是我应该在模型或控制器中初始化 DOMdocument 吗?该应用程序将在浏览器中加载文件后生成文件,因此我认为在控制器中执行此操作是最好的方法。也许像下面这样:

class Main extends Controller {

    public function index()
    {
        $feed = $this->loadDOMdocument('name');
        $feed->saveDOMdocument();
    }

}

这两个方法将在控制器文件中声明。只是寻找一些最好的建议就是去做这个。

谢谢

就用文档吧,我就是这么干的,以前没用过这个框架:

The View is the information that is being presented to a user. A View will normally be a web page, but can be any type of "page".

另见 http://gilbitron.github.io/PIP/#views。是控制器:

class Main extends Controller {

    function index()
    {
        $template = $this->loadView('main_view');
        $template->render();
    }

}

因此,创建一个 XmlFeedView 或在此框架中按照惯例调用的任何内容,并将其加载到控制器中。并在视图 class.

中使用 DOMdocument