任何人都可以帮我理解这段代码及其出现错误的原因吗?
遇到PHP错误
严重性:注意
消息:未定义的变量:plain_pass
文件名:views / editusers.php
行号:59
第59行:
<td> <input type="password" name="password" value="<?php echo $plain_pass; ?>"> </td>
控制器/ Cpages.php
public function editusers() {
$user_id = $this->uri->segment(3);
$data['users'] = $this->Mpages->call_point_users($user_id);
foreach($users as $users_item) {
$encrypt_pass = $users_item['password'];
$plain_pass = $this->encrypt->decode($encrypt_pass);
}
$this->load->view('editusers', $data, $plain_pass);
}
视图/ editusers.php
<div class="widget-box">
<div class="widget-title"><h5>Users</h5></div>
<div class="widget-content">
<?php echo form_open('cpages/editusersdb'); ?>
<table border="0" style="width: 100%; height: 90px;">
<tr>
<td>NAME</td>
<td><input type="text" name="fname" value="<?php echo $users_item['username']; ?>"></td>
</tr>
<tr>
<td>EMAIL</td>
<td><input type="text" name="fname" value="<?php echo $users_item['email']; ?>"></td>
</tr>
<tr>
<td>PASSWORD</td>
<td><input type="password" name="password" value="<?php echo $plain_pass; ?>"></td>
</tr>
<tr>
<td>ROLE</td>
<td>
<select>
<optgroup>
<option value="Administrator">Administrator</option>
<option value="Manager">Manager</option>
</optgroup>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" class="edit" name="submit" value="SUBMIT"></td>
</tr>
</table>
</div>
<?php endforeach; ?>
答案 0 :(得分:2)
将$ plain_pass放入数据数组中。
public function editusers() {
$user_id = $this->uri->segment(3);
$data['users'] = $this->Mpages->call_point_users($user_id);
foreach($users as $users_item) {
$encrypt_pass = $users_item['password'];
$plain_pass = $this->encrypt->decode($encrypt_pass);
}
$data['plain_pass'] = $plain_pass;
$this->load->view('editusers', $data);
}
答案 1 :(得分:1)
我找到的最佳方式
$data['users'] = array();
$results = $this->Mpages->call_point_users($user_id);
if (isset($results)) {
foreach ($results as $result) {
$data['users'][] = array(
'email' => $result['email'],
'username' => $result['username'],
'encrypt_pass' => $result['password'],
'plain_pass' => $this->encrypt->decode($result['encrypt_pass'])
);
}
}
$this->load->view('someview', $data);
没有两种类型的通行词只有一种。还有codeigniter 加密不是密码的代码,因为它可以被解密, 而是使用像
这样的东西http://php.net/manual/en/function.password-hash.php并进行验证 http://php.net/manual/en/function.password-verify.php varchar 255
查看
<table>
<thead>
</thead>
<tbody>
<?php foreach ($users as $user) {?>
<tr>
<td>NAME</td>
<td><input type="text" name="username" value="<?php echo $user['username']; ?>"></td>
</tr>
<tr>
<td>EMAIL</td>
<td><input type="text" name="email" value="<?php echo $user['email']; ?>"></td>
</tr>
<tr>
<td>PASSWORD</td>
<td><input type="password" name="password" value="<?php echo $user['plain_pass']; ?>"></td>
</tr>
<?php }?>
</tbody>
</table>