简体   繁体   English

将参数从视图传递到joomla中的模型

[英]Pass parameters from view to model in joomla

In a joomla custom made component there are multiple posts on a page, and every post contains multiple comment, so in view i want to call comments by post id. 在joomla定制组件中,页面上有多个帖子,每个帖子都包含多个评论,因此在视图中我想通过帖子ID调用评论。 please suggest a good method to make it working. 请提出一种使它正常工作的好方法。

You have two options. 您有两个选择。 The first, is to attach the comment id as a URL paramater and retrieve it within the model as needed like so: 首先,将注释id作为URL参数附加,并根据需要在模型中检索它,如下所示:

$comment_id = JRequest::getApplication()->input->get('comment_id');

If you wish to pass in a parameter when calling the model from the view class, you need to get an instance of the MVC path model instead of using the short cut method. 如果希望在从视图类调用模型时传递参数,则需要获取MVC路径模型的实例,而不是使用快捷方式。 So, instead of using this in the JView class: 因此,不要在JView类中使用它:

 $this->items = $this->get('Items');

You would do this instead: 您可以改为:

$model = $this->getModel();
$this->items = $model->getItems($comment_id);

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM