Prefixes

From RedBean

Jump to: navigation, search

Table Prefixes

RedBean offers an easy way to determine how your tables and primary IDs will look like in the database. This is done using the Bean Formatter.

A Bean Formatter is an object that formats the bean in the database. It has to implement two methods:

  • formatBeanTable
  • formatBeanID

For instance to prefix all tables with the word 'CMS' and all IDs with their table name:

class MyBeanFormatter implements RedBean_IBeanFormatter{
public function formatBeanTable($table) {
return "cms_$table";
}
public function formatBeanID( $table ) {
return "{$table}_id"; // append table name to id. The table should not inclide the prefix.
}
}

And then pass an instance of the new formatter to the writer using:

R::$writer->setBeanFormatter(new MyBeanFormatter());
Personal tools