SamC Posted September 21, 2016 Share Posted September 21, 2016 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 More sharing options...
LostKobrakai Posted September 21, 2016 Share Posted September 21, 2016 Both things are not really php specific, but more common oop concepts. They're certainly not pw specific. http://php.net/manual/en/language.oop5.typehinting.phphttp://php.net/manual/en/internals2.opcodes.instanceof.php 2 Link to comment Share on other sites More sharing options...
SamC Posted September 21, 2016 Author Share Posted September 21, 2016 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 More sharing options...
LostKobrakai Posted September 21, 2016 Share Posted September 21, 2016 I'm not sure renderNav() does work with a native array, but $pages->find('something') will return a PageArray object anyways. Link to comment Share on other sites More sharing options...
renobird Posted September 21, 2016 Share Posted September 21, 2016 Just read that PHP 7 will throw a TypeError exception now, instead of a fatal error. That is a little friendlier to work with. 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