I'm using myth auth library to my login form. When I ran the login it said:
ErrorException Undefined variable: config
here are the code for my view l
<?= $this->extend($config->viewLayout); ?>
<form action="<?= base_url(route_to('login')) ?>" method="post">
<?= csrf_field() ?>
<?php if ($config->validFields === ['email']): ?>
<div class="form-group">
<input type="email" class="form-control form-control-user <?php if(session('errors.login')) : ?>is-
invalid<?php endif ?>" name="login" placeholder="<?=lang('Auth.email')?>">
<div class="invalid-feedback">
<?= session('errors.login') ?>
</div>
</div>
<?php else: ?>
<div class="form-group">
<input type="text" class="form-control <?php if(session('errors.login')) : ?>is-invalid<?php endif ?
>" name="login" placeholder="<?=lang('Auth.emailOrUsername')?>">
<div class="invalid-feedback">
<?= session('errors.login') ?>
</div>
</div>
<?php endif; ?>
In my case, once logged on, it redirected back to the login page with the error above. To solve the issue, I create a public constructor which contains the variable config and pass the variable to the login view.
Public constructor method:
public function __construct()
{
$this->session = service('session');
$this->config = config('Auth');
$this->auth = service('authentication');
}
Public index method:
{
$data = [
'config' => $this->config
];
return view('/forms/login', $data);
}
myth\auth\src\convig\auth line 50
public $validFields = [
'username', 'email'
];
Don't remove 'email'.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.