Jump to content

Optimal Way To Structure Pages... (Page Reference vs Children)


awesomolocity
 Share

Recommended Posts

Alright. So I'm converting a site I already have to Processwire (really enjoying it so far!). I wanted to convert the previous tables that I had data in to Processwire pages. But I'm wondering what the optimal way to structure pages would be.

 

So basically, I have three main tables.

Users (and all accompanying information)

Items (and all accompanying information)

Aquariums (each user only has 1 aquarium. Currently, user_id is a FK)

Fish (type of item. Aquariums may have multiple fish)

Aqua_settings (Things like lightness, temperature, etc)

 

So in my current setup, there are a lot of Foreign Keys. I could accomplish essentially the same thing by using the Page Reference field.

Alternatively, I could make fish and aqua_settings both be children of Aquarium. I could differentiate by doing $aquarium->children('template=aqua_settings'); or something.

 

So my question is...should I be using the Page Reference field or structuring the pages as children? (Or are both equally fine depending on how I want to go about doing things)

  • Like 1
Link to comment
Share on other sites

Welcome to the Forums @awesomolocity

The simplest setup utilizes the fact that setting up the Page Tree also means setting up ProcessWire's default router. If you do now want to implement "fancy" routing then I recommend using the Page Tree for that and that will also define what needs to be accomplished with page reference fields.

Link to comment
Share on other sites

Child pages can be good when:

  1. You think it will be helpful for the relationship to be shown in the URL to the pages: /manufacturers/dodge/challenger/
    Although it is also possible to 'fake' a page URL using URL segments.
  2. The child will exclusively belong to that parent (it doesn't belong to multiple categories).

If either of these is not the case then you are better off with Page Reference fields. So in your example, you have fish in an aquarium. If by "fish" you mean "species of fish" then you wouldn't want to have these as child pages of an aquarium, because multiple aquariums might have the same species of fish and you don't want to duplicate the species pages.

 

  • Like 1
Link to comment
Share on other sites

I have kind of the same website like you about turtles. https://chrysemys.nl

I have a mix of parent/child pages and page references. Alle depending on the specific needs.

 

If a fish could change owner or change aquarium, I would use page reference. User can change this themselves, otherwise you would need to give them too much permissions.

 

I have the taxonomy for turtles. order -> sub order -> family -> species. This is a parent/child tree as these a vast routes that are always the same for a turtle.

The same goes for the country or origin: region -> country.

 

Page reference can also be bidirectional. This is very usefull!

If you have books on your site you can reference to the fish in that book. In the admin you will see on the fish page all books and on the book page all fish.

If you add a new book and select a few fish, that book is also added to those fish in the admin fish page.

 

That way you can make an amazing flexible website

To be honest it took me a while to figure it all out. I used to have all page references but later changes some part to parent/child. This because it would make it less possible to make mistakes. For example, I added some countries to a turtle but also referenced the wrong region. Therefor that turtle would appear on wrong pages. Using the parent/child for this made it more dummy proof ;)

 

 

  • Like 2
Link to comment
Share on other sites

On 10/2/2017 at 10:09 PM, webhoes said:

Page reference can also be bidirectional. This is very usefull!

If you have books on your site you can reference to the fish in that book. In the admin you will see on the fish page all books and on the book page all fish.

If you add a new book and select a few fish, that book is also added to those fish in the admin fish page.

Can you please elaborate on this? Besides using this one: https://modules.processwire.com/modules/connect-page-fields/ what else is available? Also, there is this no longer maintained module http://modules.processwire.com/modules/page-references-tab/ ?

Am I misunderstanding something here?

Link to comment
Share on other sites

I use ConnectPageFields and it works on the latest version.

Let's say you have 50 types of fish on your site.

You add a new book and reference all these fish to that book. If add a new fish and you want to reference it to that same book you would also need to edit that book.

With bidirectional link you reference the book when you add the fish. No need to go to the book afterwards.

With a few fish and books that's would not be a problem, but if you have more of 50 of each, this would make you live easier.

With a bidirectional link both references are visible on both pages in the admin. If you delete one, the other will also be deleted.

 

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

×
×
  • Create New...