Loading data for a page, based on an ID in the querystring

Let’s say I am passing some form of id to a page in a querystring i.e. ?id=1234. I want to load data, based on that id, from PHP, that I can then use to populate fields on the page. This includes “complex” data, meaning there is some calculation/processing necessary to figure out the value of some fields. Some of these fields may be muti-value ie. likely arrays, which logically define a parent/child-like relationship with the id.

I am looking for some sort of pattern for creating this sort of page.

. On loading the page, I invoke some PHP function to extract the id from the querystring and then retrieve and calculate the values, to be presented in the fields on the page.

. Prepare this data so the various properties are is easily available for me in the builder as dynamic data i.e. I can reference a calculated property for each field.

At a high level, my thinking is that, on being loaded, my page would use initialize a variable that is an instance of a class that encapsulates this, exposing each calculated field as a public property.

  1. How/where can I invoke a function to instantiate and initialize a variable of that class on page load?
  2. How can I then reference the public properties of that class from the builder?

I sense there are features in Bricks or an approach I am missing here. I’d appreciate any guidance on this.