ModX Revo getimagelist snippet. How can I search for a string in the field?

612 Views Asked by At
$output = $modx->runSnippet('getImageList',array(
   'tvname' => 'workOrders',
    'where' => $_GET['search'] ,
   'tpl' => 'workOrdersList',
   'docid' => 3
));

One of the fields is a string with parameters. How can I check whether my search string is a part of that field? I have looked up how to use "where" parameter to accomplish this task but I am still stuck.

2

There are 2 best solutions below

0
On BEST ANSWER

If you just use this extra (getUrlParam), you can call this instead of refering to the GET directly:

So your call could look like this:

$output = $modx->runSnippet('getImageList', array(
    'tvname' => 'workOrders',
    'where' => $modx->runSnippet('getUrlParam', array('name' => 'search`)),
    'tpl' => 'workOrdersList',
    'docid' => 3
));

This also takes care of malicious url parameters.

1
On

Where needs to be formatted as a JSON value, so you would need to define which field you are querying against and format as JSON. E.g. 'where' => $modx->toJSON(array('pagetitle'=>$_GET['search']))