i have create a page, i link the page on my navigation bar. when i click the link the it displays page not found. i duplicated the code for the login system but for a different account but it seems not to find this particular page , but the original login page works fine
<?php
namespace common\models;
use Yii;
use yii\base\Model;
/**
* Login form
*/
class DocLoginForm extends Model
{
public $username;
public $password;
public $rememberMe = true;
private $_doctor;
/**
* {@inheritdoc}
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
<?php
namespace common\models;
use Yii;
use yii\base\Model;
/**
* Login form
*/
class DLoginForm extends Model
{
public $username;
public $password;
public $rememberMe = true;
private $_doctor;
/**
* {@inheritdoc}
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
namespace common\models;
use Yii;
use yii\base\Model;
/**
* Login form
*/
class DLoginForm extends Model
{
public $username;
public $password;
public $rememberMe = true;
private $_doctor;
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$doctor = $this->getUser();
if (!$doctor || !$doctor->validatePassword($this->password)) {
$this->addError($attribute, 'Incorrect username or password.');
}
}
}
/**
* Logs in a user using the provided username and password.
*
* @return bool whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
}
return false;
}
/**
* Finds user by [[username]]
*
* @return |null
*/
protected function getUser()
{
if ($this->_doctor === null) {
$this->_doctor = Doctor::findByUsername($this->username);
}
return $this->_doctor;
}
}
the controller method is below
public function actionDocLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new DloginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
$model->password = '';
return $this->render('dlogin', [
'model' => $model,
]);
}
}
when i login im getting an error , Exception (Unknown Property) ‘yii\base\UnknownPropertyException’ with message ‘Getting unknown property: common\models\DloginForm::auth_key’.
i managed to solve the error i was getting about the attribute auth_key . on the other hand i can now log in into my doctor account but there is this thing that is happening when i refresh , i get sent back to another user account which is not doctor, the account is from the user table .
about my design i trying to have three accounts that sign-in separately and have three different views, these three would be doctor , farm and customer.
That’s exactly what I was afraid of.
It is probably because a user shares the same ID of that doctor.
In your design, doctors are defined in doctor table. And the ID of a doctor is unique among doctors. But some farm or customer may have the same ID, because they are defined in another table.