#1
17 марта 2021 в 16:00
Всем привет. Есть ли в системе метод вывода виджета по его id?
#2
17 марта 2021 в 16:23
Lora, нету, я делал примерно так
public function actionRelated() { $bind_id = $this->request->get('bind_id'); $item_id = $this->request->get('item_id'); cmsCore::error404(); } $model = new cmsModel(); $widget_array = $model->getItemById('widgets_bind', $bind_id, function($item, $model) { $item['options'] = cmsModel::yamlToArray($item['options']); $item['groups_view'] = cmsModel::yamlToArray($item['groups_view']); $item['groups_hide'] = cmsModel::yamlToArray($item['groups_hide']); $item['languages'] = cmsModel::yamlToArray($item['languages']); $item['template_layouts'] = cmsModel::yamlToArray($item['template_layouts']); $item['device_types'] = cmsModel::yamlToArray($item['device_types']); return $item; }); if (!$widget_array) { cmsCore::error404(); } //чтобы получить больше данных $oldLimit = $widget_array['options']['limit']; $widget_array['options']['limit'] = 66; //чтобы не было ошибок $widget_array['controller'] = 'content'; $widget_array['name'] = 'list'; $widget_array['is_cacheable'] = false; $widget_array['bind_id'] = $widget_array['id']; //ну и получим данные об открытой записи тк $item = $model->getItemById('con_news',$item_id); if (!$item) { cmsCore::error404(); } $item['ctype_name'] = 'news'; cmsModel::cacheResult('current_ctype_item', $item); //подсмотрено в cms_core->runWidget и cms_template->renderWidget $widget = cmsCore::getWidgetObject($widget_array); //чтобы в list_tiles_news отличить этот запрос $widget->oldLimit = $oldLimit; if($data === false){ cmsCore::error404(); } $tpl_path = cmsCore::getWidgetPath($widget->name, $widget->controller); $tpl_file = $this->cms_template->getTemplateFileName($tpl_path . '/' . $widget->getTemplate()); $data['widget'] = $widget; $this->cms_template->processRender($tpl_file, $data); }
#3
17 марта 2021 в 17:06
Ок, понятно.Спасибо, Zau4man,