Yii Framework Forum: Saas Using Mysql Multi Tenant Strategy For Saas Using Mysql - Yii Framework Forum

Jump to content

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

Saas Using Mysql Multi Tenant Strategy For Saas Using Mysql multi tenant strategy for saas using mysql Rate Topic: -----

#1 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 20-April 11
  • Location:India

Posted 08 October 2012 - 05:17 AM

Saas Using Mysql - multi tenant strategy for saas using mysql

How we create a SaaS app using Yii?

can anything do with extends CActiveRecord ??
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#2 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 20-April 11
  • Location:India

Posted 08 October 2012 - 05:32 AM

i want to read the data of the current db user only...im saving the current username by a trigger ..

any simple method?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#3 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 20-April 11
  • Location:India

Posted 08 October 2012 - 05:56 AM

any idea?

class Content extends CActiveRecord
{
    public function defaultScope()
    {
        return array(
            'condition'=>"language='".Yii::app()->language."'",
        );
    }
}

Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#4 User is offline   filthy 

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

Posted 08 October 2012 - 07:30 AM

View PostRajith R, on 08 October 2012 - 05:32 AM, said:

i want to read the data of the current db user only...im saving the current username by a trigger ..

any simple method?


IN the code below, i am using tenant_id to separate the records.

beforeSave() method in model to populate with current username. Example:

	public function beforeSave()
	{
		if($this->isNewRecord)
		{
			$this->user_created=Yii::app()->user->name;
			$this->tenant_id = Yii::app()->user->tenantId;
			$this->project_id = Yii::app()->user->projectId;
		}
		else
		{	
			$this->date_updated=new CDbExpression('NOW()');
			$this->user_updated=Yii::app()->user->name;
		}
		return true;
	}





and defaultScope() method to always retrieve record with current username. ex:

      public function defaultScope()
	{
		return array(
			'condition'=>'tenant_id='.Yii::App()->user->tenantId,
                        'order'=>'change_request_status_id ASC, name DESC'
		);
	}

2

#5 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 20-April 11
  • Location:India

Posted 09 October 2012 - 01:28 AM

so which is better approach override or change the CActiveRecord ?

change CActiveRecord like this or ??
protected function beforeSave()
	{
                $this->tenant_id = Yii::app()->user->tenantId;

		if($this->hasEventHandler('onBeforeSave'))
		{
			$event=new CModelEvent($this);
			$this->onBeforeSave($event);
			return $event->isValid;
		}
		else
			return true;
	}


and change CActiveRecord

public function defaultScope()
        {
                return array(
                        'condition'=>'tenant_id='.Yii::App()->user->tenantId,
                        
                );
        }


is this ok?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
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