Yii Framework Forum: multi tenant architecture - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

multi tenant architecture Rate Topic: -----

#1 User is offline   filthy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 27-January 12

Posted 13 February 2012 - 08:41 PM

How would i build a multi tenant architecture using YII?

I have a database. all tables have a tenant_id which identifies/segregates data to a single tenant.

example: ... projects table (id, name, tenant_id)

my approach, (pseudo code)

On login, set session(tenant) to user.tenant_id.
When display data, select data where tenant = session variable.
on insert/update, delete, get user.tenant (make sure it is the correct tenant), then do action.

questions:

1. is session variable a viable choice? session variable is unstable in my experience.
2. how can i set session variable condition (as in default scope) once and not in every single model?
3. any other way that would make this easier/more secure? What are you doing?
0

#2 User is offline   waitforit 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 09-February 11

Posted 13 February 2012 - 08:43 PM

This is what defaultScope is made for. Read some of my posts on this topic for more information.

Make a base model with a defaultScope. Inherit from this model when you want the scope, don't inherit from it when you don't. Or, disable the defaultScope as needed.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users