palacios000 Posted November 4, 2014 Share Posted November 4, 2014 hello! I can't wait to see my first PW project wheeling on the net. Before that I need to solve some problems to understand the big picture. let's say I am trying to organise a directory of hotels, several hotels share the same information (check-in, check-out, etc) depending from supplier. What I've done is have a template for "hotels" and one for "suppliers". In the "hotels" template I have a 'field' type 'page' (i named it: blng_supplier) where I can select which supplier to associate to the hotel. then I wrote $supplier = $page->blng_supplier; // here I'm on the hotel page echo $supplier; // it outputs supplier page-id number: 1234 echo $pages->get($supplier)->supp_check_in; // nothing happens ... echo $pages->get(1234)->supp_check_in; // it works! So I'm bit lost now.. what is the best way to get other variables from another page/template? thanks in advace! Link to comment Share on other sites More sharing options...
kongondo Posted November 4, 2014 Share Posted November 4, 2014 Welcome to PW and the forums palacios000.Your $supplier is in PHP terms an object. With that, you have all attributes of that object at your disposal; its id, name, title, parent, children, when it was created - everything . So all you need to do is, e.g. echo $supplier->title; //or echo $supplier->supp_check_in;//No need to do the $pages->get(1234) again. Here I assume I assume blng_supplier is a single page field. If it is a multiple page field, you would have to loop through it.. 2 Link to comment Share on other sites More sharing options...
palacios000 Posted November 5, 2014 Author Share Posted November 5, 2014 WOW! even easier then I thouhght.. well done PW and thank you for reply! Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 5, 2014 Share Posted November 5, 2014 I'll just add why your code does not work, as you'd expected it: If you echo a variable in php it's first forced to be converted to a string type, because objects can't be echo'd. A page-object defaults to convert to the page id. In your $pages->get($something) call theres no conversion happening like before, that's why there's nothing found. The method $pages->get() either expectes a id in form of an integer or a selector in form of a string, the page object is neither of both. echo $pages->get($supplier)->supp_check_in; // nothing happens, because there's an object provided echo $pages->get(1234)->supp_check_in; // it works, because there's an integer provided echo $pages->get((int)$supplier)->supp_check_in; // works, too, because the object is first converted to an integer 2 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