Jump to content

Hooking into $->find() query parsing function/object


Adam Kiss
 Share

Recommended Posts

Hey Ryan,

I'd like to use Processwire's query parsing functions (or object implementation), which are already implemented to parse module's settings, and parse something else.

So what do I need to do, if I have string like

customthing=1|2|3, anotherstuff=1

and I would like to receive object (or array) with customthing and anotherstuff as keys and the rest like their values?

Thanks

Link to comment
Share on other sites

Adam you want to use the Selectors class. Try running this example, which should answer a lot of questions:

$str = "a=1|2|3, b<=1, c*=xyz|some, d>10, e|f=something, g!=nothing";
$selectors = new Selectors($str); 

$tests = array('0', '1', '3', '9', '15', 'Adam', 'abcdefghijklmnoprstuvwxyz', 'something', 'nothing');

echo "<ul>";
foreach($selectors as $s) {

   echo "<li>" . $s; 
   echo " (" . $s->field . $s->operator . $s->value . ")"; 
   echo "<ul>";

   foreach($tests as $test) {
       $matches = $s->matches($test) ? "<strong>Matches</strong>" : "Does not match";
       echo "<li>$matches: $test</li>";
   }

   echo "</ul></li>";
}
echo "</ul>";
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...