Jump to content

Function arguments question


SamC
 Share

Recommended Posts

Hi,

Been away for awhile focussing on javascript but need to actually make a site now and was impressed with processwire a few months back when I was messing about with it. So I've cleverly started with a blank site with the hope that I can learn a lot more than starting with a half built one. I'm looking at the example functions in _func.php (from my previous site, my current _func.php is blank of course) and have a question about the functions:

function renderNav(PageArray $items) {

Why is 'PageArray' in there? Is that just to make one aware that this argument wants an array? Or does it do something else? Bear in mind PHP isn't what I'd call my strong point.

and

function renderNavTree($items, $maxDepth = 0, $fieldNames = '', $class = 'nav') {

    // if we were given a single Page rather than a group of them, we'll pretend they
    // gave us a group of them (a group/array of 1)
    if($items instanceof Page) $items = array($items);

Same here with '$items instanceof Page)'. Never seen anything like it, is it a PHP thing or a built-in processwire thing?

I'm hitting up the cheatsheet and echoing out a load of built-in field references to see what they return whilst on various pages before I actually try and build a simple 1st level navigation, then a second submenu which lists child pages of the current parent page (which also stays visible when on the child pages themselves). I don't really want to use a module as it would teach me nothing. Anyway, going off subject here, the menu is for another thread when I undoubtedly get stuck.

Thanks for any advice.

 

 

 

 

Link to comment
Share on other sites

Thanks for the info. I wondered if the function expected an array, why not:

function renderNav(array $items) {

...but now I see 'PageArray' here:

https://processwire.com/api/arrays/page/

And I'm guessing:

if($items instanceof Page) $items = array($items);

...refers to an object which is an instance of a class named 'Page':

https://processwire.com/apigen/class-Page.html

Makes more sense now (if I'm correct that is). Thanks.

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