Answer the question
In order to leave comments, you need to log in
How to pass data to yii2?
How to pass data from web.php component like this
'components' => [
'user' => [
'class' => 'register\setUser',
'username' => 'login',
'password' => 'password_user',
]
]
Answer the question
In order to leave comments, you need to log in
First, take a look at the Service-locator
link
This is how configs work. Data from configs is passed to constructors using configuration objects.
And then - tell me, is this such a strange example for you to show what data you want to transfer, or are you seriously going to use such a user component?
At a minimum, the login-pass of the test user should be stored at least in the local file, because locally you can have one username-password, and in production - another.
And here is this link - more details on how to pass data to components
Regarding the login and the standard User component, everything is simple:
But it's not possible to set it from the config. In general, if your class has a public variable
and it is defined in the config:
'components' => [
'user' => [
'class' => 'register\setUser',
'moyaHren' => 'балалайка',
]
]
public $moyaHren;
public function getChiyaOna($my='моя',$color="зеленовая"){
return $my . ' ' . $color . ' ' . $this->moyaHren;
}
echo Yii::$app->user->getChiyaOna('его');
// получите "его зеленовая балалайка"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question