Jump to content

Selectors can only be strings, newlines make selectors buggy


theoretic
 Share

Recommended Posts

Hi there! And thanks for Processwire!

It appears that i've found something interesting about PW selectors. They should only be strings! Here's an example of SQL-like syntax for selector:

$my_complex_selector = "
name='some name',
parameter=123,
other_parameter=[subparam>=subvalue]
";

Trying to use this selector lead to a very buggy PW behaviour. It appears that newlines are treated in a very special manner by PW selector engine, preventing the newlined selectors from working as expected.

I cannot imagine a situation when an unescaped newline could be a part of selector or selector value, so stripping newline symbols from selector could be a good idea for further PW development. And, currently, another good idea is to write complex selectors as PHP arrays:

$my_complex_selector = [
"name=$name",
"param1=$param1",
];

and to implode them into a single line before using find() and other functions which use selectors.

Sorry if i wrote something trivial, but having this post already present at support forum could save me a couple of hours. Hope mine will save that tame for someone else ?

Link to comment
Share on other sites

@Zeka, thanks! The built-in selector array representation is good for relatively simple queries. But i couldn't find any example of correct select array syntax for cases like

my_repeater = [ my_repeater_field1=value1, my_repeater_field2>value2, my_repeater_field3%=value3 ]

I suppose that there's some array syntax for cases like this but i could'n find it.

Link to comment
Share on other sites

8 minutes ago, theoretic said:

@Zeka, thanks! The built-in selector array representation is good for relatively simple queries. But i couldn't find any example of correct select array syntax for cases like


my_repeater = [ my_repeater_field1=value1, my_repeater_field2>value2, my_repeater_field3%=value3 ]

I suppose that there's some array syntax for cases like this but i could'n find it.

You might find what you need in this post: https://processwire.com/talk/topic/19024-selector-arrays-with-page-reference-fields-with-and-not-or/

  • Like 2
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...