vx\tr classes

In version 1.3.1255 the vx\tr namespace was added to the Vortex when the need for easier access to TableRecords was noted. The Vortex dynamically creates classes in the vx\tr namespace for every table, giving the class the same name as the table. There are a few reserved words in PHP preventing classes with names like switch, and etc from being created, and for tables having a reserved name the name will be prefixed with vx_, so the table switch would have a class called vx\tr\vx_switch.

To fetch a TableRecord a new instance of that tables class is created, passing a filter condition to the constructor. If the passed condition is an instance of the FilterData or Filter class, that filter will be applied to the search and the first match will be returned. If the condition is a string it will be treated as a SearchString returning the first match. If no TablRecords are found matching the condition, a new TableRecord will be created and the $newpost attribute of the TableRecord will be set to true.

Fetching the first computer with a specific IP number would be:

  $computer = new vx\tr\computer( "[ip=\"192.168.0.10\"]" );

Getters and setters

At the same time as the vx\tr namespace was added, getters and setters was added for all fields in the TableRecord. For example getting a computer with a specific IP and creating it if it didn't exist would look like:

  $computer = new vx\tr\computer( "[ip=\"192.168.0.10\"]" );
  if( $computer->newpost ) {
    $computer->ip = "192.168.0.10";
    $computer->save();
  }
  echo $computer->ip;

If the field set doesn't exist the value will be stored in a temporary attribute which will not be stored to the database, but will exist for the duration of this session or until the TableRecord is garbage collected or destroyed.