Jump to content

Selectors class object -- how to get string property?


hellomoto
 Share

Recommended Posts

https://processwire.com/api/ref/selectors/

Is it not possible to access the `string` property? `$selectors->count` works, and $selectors->getArray() works for items. How is the string accessed? I've tried ->getProperty('string'), and I don't remember what else...

The class has a selectorStr property but it's protected?

Edited by hellomoto
Link to comment
Share on other sites

In the Selectors class definition, Ryan wrote that the protected property "selectorStr" there only for debugging.
I tried with $selectors->get("selectorStr") and it doesn’t work neither.
So if I really need that string (and couldn’t store it earlier in the process), I would create a class that extends Selectors an allow selectorStr exposure...

Link to comment
Share on other sites

On 10/27/2024 at 11:04 AM, TomPich said:

In the Selectors class definition, Ryan wrote that the protected property "selectorStr" there only for debugging.
I tried with $selectors->get("selectorStr") and it doesn’t work neither.
So if I really need that string (and couldn’t store it earlier in the process), I would create a class that extends Selectors an allow selectorStr exposure...

Okay thanks but why not just access via ->__toString()?

Link to comment
Share on other sites

You are right... 😊
Actually, _toString() is not supposed be called explicitly. It’s called when you do "echo $selectors".
So when you do "echo $selectors", you get the string you want. But it’s not returned, it’s just displayed.
Maybe you can do ob_start() and ob_get_clean() to capture the string you want in a variable.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...