<?php
namespace frontend\models;
use Yii;
/**
* This is the model class for table "user".
*
* @property int $id
* @property string $username
* @property string $auth_key
* @property string $password_hash
* @property string $password_reset_token
* @property string $email
* @property int $status
* @property int $created_at
* @property int $updated_at
* @property int $medpersonal_id
*
* @property Medpersonal $medpersonal
*/
class User extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'user';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'auth_key', 'password_hash', 'email', 'created_at', 'updated_at'], 'required'],
[['status', 'created_at', 'updated_at', 'medpersonal_id'], 'integer'],
[['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
[['auth_key'], 'string', 'max' => 32],
[['username'], 'unique'],
[['email'], 'unique'],
[['password_reset_token'], 'unique'],
[['medpersonal_id'], 'unique'],
[['medpersonal_id'], 'exist', 'skipOnError' => true, 'targetClass' => Medpersonal::className(), 'targetAttribute' => ['medpersonal_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'username' => 'Username',
'auth_key' => 'Auth Key',
'password_hash' => 'Password Hash',
'password_reset_token' => 'Password Reset Token',
'email' => 'Email',
'status' => 'Status',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
'medpersonal_id' => 'Medpersonal ID',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getMedpersonal()
{
return $this->hasOne(Medpersonal::className(), ['userID' => 'id']);
}
}
<?php
namespace frontend\models;
use Yii;
class Personal extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'personal';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['idd', 'combination'], 'integer'],
[['combination'], 'required'],
[['FIO', 'position', 'specialnost'], 'string', 'max' => 50],
[['position'], 'exist', 'skipOnError' => true, 'targetClass' => Position::className(), 'targetAttribute' => ['position' => 'position']],
[['idd'], 'exist', 'skipOnError' => true, 'targetClass' => DuobleSubLu::className(), 'targetAttribute' => ['idd' => 'id']],
[['specialnost'], 'exist', 'skipOnError' => true, 'targetClass' => Specialnost::className(), 'targetAttribute' => ['specialnost' => 'specialnost']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'FIO' => 'Fio',
'position' => 'Position',
'specialnost' => 'Specialnost',
'idd' => 'Idd',
'combination' => 'Combination',
];
}
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'userID']);
}
}
?>
$menuItems_log[] = '<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'Выход (' . Yii::$app->user->identity->username.')',
['class' => 'logout']
)
. Html::endForm()
. '</li>';
userID
? Ни в одной из предоставленных моделей нет такого атрибута.public function getPersonal()
{
retun $this->hasOne(Personal::className(), ['userID' => 'id']);
}
Yii::$app->user->identity->id
. Вот через этот параметр можно получить данные определённого пользователя из модели Personal.public static function getDataUser($id)
{
$model = Personal::find()->where('id=:id', [':id' => $id])->one();
return $model;
}
$data = Personal::dataUser(Yii::$app->user->identity->id);
echo $data->fio;
model User:
<?php
namespace frontend\models;
use Yii;
/**
* This is the model class for table "user".
*
* @property int $id
* @property string $username
* @property string $auth_key
* @property string $password_hash
* @property string $password_reset_token
* @property string $email
* @property int $status
* @property int $created_at
* @property int $updated_at
* @property int $medpersonal_id
*
* @property Medpersonal $medpersonal
*/
class User extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'user';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'auth_key', 'password_hash', 'email', 'created_at', 'updated_at'], 'required'],
[['status', 'created_at', 'updated_at', 'medpersonal_id'], 'integer'],
[['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
[['auth_key'], 'string', 'max' => 32],
[['username'], 'unique'],
[['email'], 'unique'],
[['password_reset_token'], 'unique'],
[['medpersonal_id'], 'unique'],
[['medpersonal_id'], 'exist', 'skipOnError' => true, 'targetClass' => Medpersonal::className(), 'targetAttribute' => ['medpersonal_id' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'username' => 'Username',
'auth_key' => 'Auth Key',
'password_hash' => 'Password Hash',
'password_reset_token' => 'Password Reset Token',
'email' => 'Email',
'status' => 'Status',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
'medpersonal_id' => 'Medpersonal ID',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getMedpersonal()
{
return $this->hasOne(Medpersonal::className(), ['userID' => 'id']);
}
}
Модель Personal
<?php
namespace frontend\models;
use Yii;
class Personal extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'personal';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['idd', 'combination'], 'integer'],
[['combination'], 'required'],
[['FIO', 'position', 'specialnost'], 'string', 'max' => 50],
[['position'], 'exist', 'skipOnError' => true, 'targetClass' => Position::className(), 'targetAttribute' => ['position' => 'position']],
[['idd'], 'exist', 'skipOnError' => true, 'targetClass' => DuobleSubLu::className(), 'targetAttribute' => ['idd' => 'id']],
[['specialnost'], 'exist', 'skipOnError' => true, 'targetClass' => Specialnost::className(), 'targetAttribute' => ['specialnost' => 'specialnost']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'FIO' => 'Fio',
'position' => 'Position',
'specialnost' => 'Specialnost',
'idd' => 'Idd',
'combination' => 'Combination',
];
}
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'userID']);
}
}
?>
Как заменить admin в панели меню, который отображается при авторизации на ФИО пользователя
вот код странички main.php
$menuItems_log[] = '<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'Выход (' . Yii::$app->user->identity->username.')',
['class' => 'logout']
)
. Html::endForm()
. '</li>';