Loading login_form View with Tank Auth Giving PHP Error
我正在尝试将Tank_auth视图中的login_form添加到我的HTML模板中。
当我这样做时,它会返回一些有关缺少变量的错误,而且我不确定自己在做什么错。
我的控制器:
1 2 3 4 5 6 | public function index() { $topbar['account'] = $this->load->view('auth/login_form'); $data['topbar'] = $topbar; $this->load->view('main_template', $data); } |
主模板如下所示:
1 2 3 4 5 6 7 8 | <!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head><?php echo $template['head'] ?></head> <body> <?php echo $topbar['account'] ?> </body> </html> |
加载页面时收到的错误如下:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: show_captcha
Filename: auth/login_form.php
Line Number: 47
此外,我收到以下相同的错误:
继承人登录表单(未修改...默认tank_auth表单)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | <?php $login = array( 'name' => 'login', 'id' => 'login', 'value' => set_value('login'), 'maxlength' => 80, 'size' => 30, ); if ($login_by_username AND $login_by_email) { $login_label = 'Email or login'; } else if ($login_by_username) { $login_label = 'Login'; } else { $login_label = 'Email'; } $password = array( 'name' => 'password', 'id' => 'password', 'size' => 30, ); $remember = array( 'name' => 'remember', 'id' => 'remember', 'value' => 1, 'checked' => set_value('remember'), 'style' => 'margin:0;padding:0', ); $captcha = array( 'name' => 'captcha', 'id' => 'captcha', 'maxlength' => 8, ); ?> <?php echo form_open($this->uri->uri_string()); ?> <table> <tr> <td><?php echo form_label($login_label, $login['id']); ?></td> <td><?php echo form_input($login); ?></td> <td style="color: red;"><?php echo form_error($login['name']); ?><?php echo isset($errors[$login['name']])?$errors[$login['name']]:''; ?></td> </tr> <tr> <td><?php echo form_label('Password', $password['id']); ?></td> <td><?php echo form_password($password); ?></td> <td style="color: red;"><?php echo form_error($password['name']); ?><?php echo isset($errors[$password['name']])?$errors[$password['name']]:''; ?></td> </tr> <?php if ($show_captcha) { if ($use_recaptcha) { ?> <tr> <td colspan="2"> </td> <td> Get another CAPTCHA Get an audio CAPTCHA Get an image CAPTCHA </td> </tr> <tr> <td> Enter the words above Enter the numbers you hear </td> <td><input type="text" id="recaptcha_response_field" name="recaptcha_response_field" /></td> <td style="color: red;"><?php echo form_error('recaptcha_response_field'); ?></td> <?php echo $recaptcha_html; ?> </tr> <?php } else { ?> <tr> <td colspan="3"> <p> Enter the code exactly as it appears: </p> <?php echo $captcha_html; ?> </td> </tr> <tr> <td><?php echo form_label('Confirmation Code', $captcha['id']); ?></td> <td><?php echo form_input($captcha); ?></td> <td style="color: red;"><?php echo form_error($captcha['name']); ?></td> </tr> <?php } } ?> <tr> <td colspan="3"> <?php echo form_checkbox($remember); ?> <?php echo form_label('Remember me', $remember['id']); ?> <?php echo anchor('/auth/forgot_password/', 'Forgot password'); ?> <?php if ($this->config->item('allow_registration', 'tank_auth')) echo anchor('/auth/register/', 'Register'); ?> </td> </tr> </table> <?php echo form_submit('submit', 'Let me in'); ?> <?php echo form_close(); ?> |
希望有人熟悉Tank Auth,可以轻松解决此问题。
谢谢。
首先请检查身份验证控制器如何使用登录并将show_captcha传递给您login_form视图,您没有将show_captcha传递给login_view
1 2 3 4 5 6 7 8 | $login_data['login_by_username'] = ($this->config->item('login_by_username','tank_auth') AND $this->config->item('use_username','tank_auth')); $login_data['login_by_email'] = $this->config->item('login_by_email', 'tank_auth'); $login_data['show_captcha'] = FALSE $topbar['account'] = $this->load->view('auth/login_form',$login_data); $data['topbar'] = $topbar; $this->load->view('main_template', $data); |
它不会显示验证码,但我建议您遵循"谢谢验证"的验证控制器的登录方法