thomas Posted January 17, 2013 Share Posted January 17, 2013 Hello, I need to build a combination of selectors which need to be in almost every find() statement on my site. Being lazy by nature, I was hoping for a way to make my life easier. I thought of three ways: - Hook after find, then find again with the new selectors. This works, but it scares me. Maybe it's not as bad performance wise as I think but my guess is, it is. - Build a property by which to find(). I liked this idea until I found out it doesn't work. The idea was to addHookProperty to Page, and then include this into find. But find only likes fields so no luck. - Hook before find and modify the argument passed to find(). I couldn't get this to work: $event->setArgument(0,"mySelector==yes,".$event->arguments[0]); $event->return = $event->arguments; What am I doing wrong? What are your ways of managing silly recurring selectors? Any thoughts on my ideas? Thanks! thomas Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 17, 2013 Share Posted January 17, 2013 (edited) I don't think I ever had something like this, but I imagine I'd do it with small module; // module class MySelect { public function __construct(){ // } public function findFiltered($selector){ return wire('pages')->find('limit=1,'.$selector); } } // template $mySelect = $modules->get('MySelect'); $pages = $mySelect->findFiltered('template=subselection'); Edited January 17, 2013 by adamkiss Fixed the code to something what should really work, duh Link to comment Share on other sites More sharing options...
ryan Posted January 18, 2013 Share Posted January 18, 2013 $event->setArgument(0,"mySelector==yes,".$event->arguments[0]); $event->return = $event->arguments; I'm not sure that I totally understand the example, and think I'd need to see the rest of the class to get the right picture. But there is no "==" operator in selectors, so that's one potential problem. Another is that you are assigning $event->return = $event->arguments. Why -- I don't understand this? Link to comment Share on other sites More sharing options...
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