Jump to content
Дизайн и модификация IPS Community IPBSkinsBETA
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
vinegredz

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

Recommended Posts

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

 

Хочу чтобы в табличке отображались элементы, которые я передаю в 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 параметр запихнуть в табличку?

Share this post


Link to post

array ( $ids )

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

Получается

array ( '5642,452' )

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

 

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

Share this post


Link to post

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

 

{{$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.

Share this post


Link to post

{{$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

Share this post


Link to post

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

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...