PHP code example of solutosoft / yii-multitenant

1. Go to this page and download the library: Download solutosoft/yii-multitenant library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

solutosoft / yii-multitenant example snippets


class m191023_101232_create_post extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function up()
    {
        $this->createTable('post', [
            'id' =>  $this->primaryKey(),
            'title' => $this->string()->notNull(),
            'category_id' => $this->integer(),
            'content' => $this->string()            
            'tenant_id' => $this->integer(),
        ]);
        
        $this->createTable('category', [
            'id' =>  $this->primaryKey(),
            'name' => $this->string()->notNull(),            
            'tenant_id' => $this->integer(),
        ]);
    }
}


use solutosoft\multitenant\MultiTenantRecord;

class User extends MultiTenantRecord implements IdentityInterface, TenantInterface    
{
    /**
     * {@inheritdoc}
     */
    public function getTenantId()
    {
        return // logic to determine tenant from current user
    }
    
    /**
     * Finds user by username attribute
     * This is an example where tenant filter is disabled
     */
    public static function findByUsername($username)
    {
        return static::find()->withoutTenant()->where(['username' => $username]);
    }
    
    ...
    
}

use solutosoft\multitenant\MultiTenantRecord;

class Post extends MultiTenantRecord
{    
    ...   
}

class Category extends MultiTenantRecord
{    
    ...   
}