Answer the question
In order to leave comments, you need to log in
How to access desired data from a table in Yii2?
Array
(
[0] => app\models\Users Object
(
[id] =>
[username] =>
[password] =>
[authKey] =>
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 1
[username] => victor
[password] => 12344321
[authKey] => 12344321
[accessToken] => 12344321
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 1
[username] => victor
[password] => 12344321
[authKey] => 12344321
[accessToken] => 12344321
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
[1] => app\models\Users Object
(
[id] =>
[username] =>
[password] =>
[authKey] =>
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 2
[username] => admin
[password] => 123443221
[authKey] => 12344321
[accessToken] => 12344321
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 2
[username] => admin
[password] => 123443221
[authKey] => 12344321
[accessToken] => 12344321
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
)
$user = Users::find()->all();
public static function findByUsername($username)
{
$user = Users::find()->all();
foreach ($user as $usr) {
print_r($usr);
if (strcasecmp($usr['username'], $username) === 0) {
return new static($usr);
}
}
return null;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question