|
|
|
|
596
|
By defining a 'record_filter' function you can apply a forced filter, for instance to implement roles in a database system.
|
596
|
By defining a 'record_filter' function you can apply a forced filter, for instance to implement roles in a database system.
|
597
|
The rule "you cannot view unpublished blog posts unless you have the admin role" can be implemented with this filter.
|
597
|
The rule "you cannot view unpublished blog posts unless you have the admin role" can be implemented with this filter.
|
598
|
|
598
|
|
599
|
-```return ($table=='posts' && $_SESSION['role']!='admin')?array('published,nis,null'):false;```
|
|
|
|
|
599
|
+```
|
|
|
600
|
+return ($table=='posts' && $_SESSION['role']!='admin')?array('published,nis,null'):false;
|
|
|
601
|
+```
|
600
|
|
602
|
|
601
|
## Multi-tenancy
|
603
|
## Multi-tenancy
|
602
|
|
604
|
|
603
|
The 'tenancy_function' allows you to expose an API for a multi-tenant database schema. In the simplest model all tables have a column
|
605
|
The 'tenancy_function' allows you to expose an API for a multi-tenant database schema. In the simplest model all tables have a column
|
604
|
named 'customer_id' and the 'tenancy_function' is defined as:
|
606
|
named 'customer_id' and the 'tenancy_function' is defined as:
|
605
|
|
607
|
|
606
|
-```return $col=='customer_id'?$_SESSION['customer_id']:null```
|
|
|
|
|
608
|
+```
|
|
|
609
|
+return $col=='customer_id'?$_SESSION['customer_id']:null
|
|
|
610
|
+```
|
607
|
|
611
|
|
608
|
In this example ```$_SESSION['customer_id']``` is the authenticated customer in your API.
|
612
|
In this example ```$_SESSION['customer_id']``` is the authenticated customer in your API.
|
609
|
|
613
|
|