Jump to content

Where do I find the FIND function in the skyscrapers demo?


Chris Rosenau
 Share

Recommended Posts

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

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!

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