1. Go to this page and download the library: Download daydiff/yii2-auth-chain 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/ */
daydiff / yii2-auth-chain example snippets
//Member.php
namespace app\foo\bar;
class Member implements \Daydiff\AuthChain\MemberInterface
{
private $id;
private $login;
/**
* @inheritdoc
*/
function getId()
{
return $this->id;
}
/**
* @inheritdoc
*/
function getLogin()
{
return $this->login;
}
/**
* @inheritdoc
*/
function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @inheritdoc
*/
function setLogin($login)
{
$this->login = $login;
return $this;
}
}
php
public function actionAuthAs($id)
{
$user = \Yii::$app->getIdentity()->getUser();
$member = new app\foo\bar\Member();
$member->setId($user->id)
->setLogin($user->login);
\Yii::$app->authChain->push($member);
//and then you do authorization work
}