Zah*_*yed 1 php joomla joomla-component joomla2.5
在 joomla 定制组件中,页面上有多个帖子,每个帖子都包含多个评论,因此在视图中我想通过帖子 id 调用评论。请建议一个让它发挥作用的好方法。
你有两个选择。第一种是将评论 ID 作为 URL 参数附加,并根据需要在模型中检索它,如下所示:
$comment_id = JRequest::getApplication()->input->get('comment_id');
Run Code Online (Sandbox Code Playgroud)
如果您希望在从视图类调用模型时传入参数,则需要获取 MVC 路径模型的实例,而不是使用捷径方法。因此,不要在 JView 类中使用它:
$this->items = $this->get('Items');
Run Code Online (Sandbox Code Playgroud)
你可以这样做:
$model = $this->getModel();
$this->items = $model->getItems($comment_id);
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。