hellomoto Posted October 26, 2024 Posted October 26, 2024 (edited) 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 October 26, 2024 by hellomoto
hellomoto Posted October 26, 2024 Author Posted October 26, 2024 Sorry, it's $selectors->__toString()
TomPich Posted October 27, 2024 Posted October 27, 2024 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...
hellomoto Posted October 29, 2024 Author Posted October 29, 2024 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()?
TomPich Posted October 29, 2024 Posted October 29, 2024 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now