Difference between #3 and #4 of
Using multiple models in an identity

Revision #4 has been created by Néstor Acevedo on Aug 30, 2024, 10:47:27 PM with the memo:

Adding a return null if the parameter $id is empty due to accessing as guest.
« previous (#3)

Changes

Title unchanged

Using multiple models in an identity

Category unchanged

How-tos

Yii version unchanged

2.0

Tags unchanged

authentication,identity

Content changed

[...]
private $_authkey;
private $_passwordHash;

public static function findIdentity($id)
{
     // We are going to login, so `$id` will be an empty string
 
        // `if (\count($parts) !== 2)` will raise an error because the parameter $id is empty
 
        if (strlen($id) === 0) {
 
            return null;
 
        }
 
        
 
$parts = explode('-', $id);
if (\count($parts) !== 2) {
throw new InvalidCallException('id should be in form of Type-number');
}
[$type, $number] = $parts;
[...]
9 2
5 followers
Viewed: 36 785 times
Version: 2.0
Category: How-tos
Written by: samdark
Last updated by: Néstor Acevedo
Created on: Oct 7, 2018
Last updated: 3 months ago
Update Article

Revisions

View all history