[英]Joomla: How to pass variables from the constructor in the model to the view?
[英]Pass parameters from view to model in joomla
在joomla定制組件中,頁面上有多個帖子,每個帖子都包含多個評論,因此在視圖中我想通過帖子ID調用評論。 請提出一種使它正常工作的好方法。
您有兩個選擇。 首先,將注釋id作為URL參數附加,並根據需要在模型中檢索它,如下所示:
$comment_id = JRequest::getApplication()->input->get('comment_id');
如果希望在從視圖類調用模型時傳遞參數,則需要獲取MVC路徑模型的實例,而不是使用快捷方式。 因此,不要在JView類中使用它:
$this->items = $this->get('Items');
您可以改為:
$model = $this->getModel();
$this->items = $model->getItems($comment_id);
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.