Php 在joomla中将参数从视图传递到模型
在joomla定制组件中,一个页面上有多个帖子,每个帖子都包含多条评论,因此在视图中,我想按帖子id调用评论。请建议一个好方法使其工作。您有两个选项。首先,将注释id附加为URL参数,并根据需要在模型中检索它,如下所示:Php 在joomla中将参数从视图传递到模型,php,joomla,joomla2.5,joomla-component,Php,Joomla,Joomla2.5,Joomla Component,在joomla定制组件中,一个页面上有多个帖子,每个帖子都包含多条评论,因此在视图中,我想按帖子id调用评论。请建议一个好方法使其工作。您有两个选项。首先,将注释id附加为URL参数,并根据需要在模型中检索它,如下所示: $comment_id = JRequest::getApplication()->input->get('comment_id'); 如果希望在从view类调用模型时传入参数,则需要获取MVC路径模型的实例,而不是使用快捷方法。因此,在JView类中不使用此选项
$comment_id = JRequest::getApplication()->input->get('comment_id');
如果希望在从view类调用模型时传入参数,则需要获取MVC路径模型的实例,而不是使用快捷方法。因此,在JView类中不使用此选项:
$this->items = $this->get('Items');
您可以这样做:
$model = $this->getModel();
$this->items = $model->getItems($comment_id);
希望这有帮助。您有两个选择。首先,将注释id附加为URL参数,并根据需要在模型中检索它,如下所示:
$comment_id = JRequest::getApplication()->input->get('comment_id');
如果希望在从view类调用模型时传入参数,则需要获取MVC路径模型的实例,而不是使用快捷方法。因此,在JView类中不使用此选项:
$this->items = $this->get('Items');
您可以这样做:
$model = $this->getModel();
$this->items = $model->getItems($comment_id);
希望这有帮助