Chris Rosenau Posted December 8, 2013 Share Posted December 8, 2013 Here is the code: // generate a list of featured skyscrapers.$skyscrapers = $page->skyscrapers->find("limit=3, sort=random");$content .= "\n<h3>Featured Skyscrapers</h3>" . renderSkyscraperList($skyscrapers, false); Even when I search all the files, I can't discover where the FIND function is. Can someone explain how $page->skyscrapers->find("limit=3, sort=random"); works? Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 8, 2013 Share Posted December 8, 2013 I don't know the skyscrapers profile. But if I see the syntax: $page->skyscrapers <--- skyscrapers must be a field of the type Page ( multipages ) stored in the current page. That field contains a Page array, which can be searched. Link to comment Share on other sites More sharing options...
Chris Rosenau Posted December 8, 2013 Author Share Posted December 8, 2013 Thanks that helps me track it down. I am exploring the demo and trying to understand how they created the functionality. Link to comment Share on other sites More sharing options...
Macrura Posted December 8, 2013 Share Posted December 8, 2013 have you checked the cheatsheet? http://cheatsheet.processwire.com/ Link to comment Share on other sites More sharing options...
Pete Posted December 9, 2013 Share Posted December 9, 2013 I think you should probably take a look at the concept behind ProcessWire first, then some of the other docs and the cheatsheet as Macrura suggest - start with the Concept page from here: http://processwire.com/api/ The Cheatsheet then gives you a look at most the possible functionality at your disposal in page templates to access your data and files. As for explaining the line of code you quoted: $skyscrapers = $page->skyscrapers->find("limit=3, sort=random"); From memory, "skyscrapers" is actually a "featured skyscrapers" field, so is just a Page field that links to other pages (probably the most useful fieldtype there is. Here is the exact translation: "For the current page (homepage in this instance), find 3 random pages from the skyscrapers field". The $skyscrapers = bit is just storing the results in a PageArray (it's in the docs linked further up my post here) that can then easily be iterated through to print whatever output you desire. If you're wondering why the demo doesn't seem to pick three random pages, I think page caching must have been accidentally left on here so it's always showing the same 3 in the demo, but that's easy to switch off The syntax is based on jQuery and aims to be human-readable. If you imagine that there are a few database tables and queries behind that code, you can easily see how quick that is to write and all without a line of SQL. You can make all sorts of queries like: $architectsCalledPaul = $pages->find("template=architect, title*=Paul"); // finds all architects (pages with the template "architect" with the name Paul somewhere in the title field // and so on... The idea behind ProcessWire is that once you've learned the basics you can build pretty complicated data structures in the admin quicker than you'd be able to writing database tables from scratch and you have a hugely powerful set of functions at your fingertips to do with that data as you please. Most folks here would agree that it has shaved hours/days/weeks/months off their site build times depending on website scale, but any time saved is good! 7 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