我正在尝试添加下拉框信息:
USERNAME EMAIL ROLE
3 user user@mail.com 12345
如何添加角色以便显示管理员或经理?而不是代码?
模型/ Mpages.php
public function add_user()
{
$options = [
'roles' => 'administrator',
];
$hash = password_hash($this->input->post('password'), PASSWORD_BCRYPT, $options);
$data = array(
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $hash,
'role' => form_dropdown('roles', $options, 'administrator')
);
return $this->db->insert('login', $data);
}
控制器/ Cpages.php
public function addusers() {
$data['successmessage'] = "";
$data['options'] = array(
'administrator' => 'Administrator',
'manager' => 'Manager',
);
$this->Mpages->add_user();
$this->load->view('addusers', $data);
}
答案 0 :(得分:0)
以下是答案:
控制器/ Cpages.php
public function addusers() {
$data['successmessage'] = "";
$data['options'] = array(
'administrator' => 'Administrator',
'manager' => 'Manager',
);
$this->Mpages->add_user();
$this->load->view('addusers', $data);
}
模型/ Mpages.php
public function add_user()
{
$options = [
'roles' => 'administrator',
];
$hash = password_hash($this->input->post('password'), PASSWORD_BCRYPT, $options);
$data = array(
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $hash,
'role' => $this->input->post('roles')
);
return $this->db->insert('login', $data);
}