Skip to content

Как передать в таблицу значение из URL параметра?

Здравствуйте, товарищи.

 

Хочу чтобы в табличке отображались элементы, которые я передаю в GET параметре. При таком URL:

 

site.ru?ids=5642,452

 

Такой код не работает (таблица пустая, но генерируется без проблем):

 

{{$ids = \IPS\Request::i()->ids;}}
{{$table = new \IPS\Helpers\Table\Content('IPS\cms\Records2', $record->url(), array(array(\IPS\Db::i()->findInSet('primary_id_field', array ( $ids )))));}}

Если явно поставить значение GET параметра в код вот так:

 

{{$ids = \IPS\Request::i()->ids;}}
{{$table = new \IPS\Helpers\Table\Content('IPS\cms\Records2', $record->url(), array(array(\IPS\Db::i()->findInSet('primary_id_field', array ( 5642,452 )))));}}

То все работает. Отсюда вопрос, как мне GET параметр запихнуть в табличку?

Featured Replies

array ( $ids )

Вы сюда подставляете значение переменной $ids

Получается

array ( '5642,452' )

Не похоже на то, что нужно.

 

Используйте explode

  • Author

Пробовал вот так:

 

{{$ids= explode(',', $ids);}}
{{$table = new \IPS\Helpers\Table\Content('IPS\cms\Records12', $row->url(), array(array(\IPS\Db::i()->findInSet('primary_id_field', $ids ))));}}

И вот так:

 

{{$ids= explode(',', $ids);}}
{{$table = new \IPS\Helpers\Table\Content('IPS\cms\Records12', $row->url(), array(array(\IPS\Db::i()->findInSet('primary_id_field', array( $ids )))));}}

Получаю всегда исключение типа OutOfRangeException. Проверял через {expression="gettype($ids)"} и уверен, что подставляется array.

{{$where = array();}}
{{if isset(\IPS\Request::i()->ids) and \IPS\Request::i()->ids}}
{{$ids = !\is_array(\IPS\Request::i()->ids) ? explode(',', \IPS\Request::i()->ids) : \IPS\Request::i()->ids;}}
{{$where[] = array(\IPS\Db::i()->findInSet('primary_id_field', array_filter($ids, 'is_numeric')));}}
{{endif}}
{{$table = new \IPS\Helpers\Table\Content('IPS\cms\Records12', $row->url(), $where);}}

Можете писать site.ru?ids=5642,452 или site.ru?ids[]=5642&ids[]=452

Если в primary_id_field содержится одно число, то вместо \IPS\Db::i()->findInSet используйте \IPS\Db::i()->in

  • Author

Спасибо. Приведенный код полностью рабочий.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.