Helo, Im new to php and CI. I just following ci tutorial here , and i got problem in this part .
Here is my model
public $rules_admin = array(
'name' => array(
'field' => 'name',
'rules' => 'trim|required'
),
'email' => array(
'field' => 'email',
'rules' => 'trim|required|valid_email|callback__unique_email'
),
'password' => array(
'field' => 'password',
'rules' => 'trim|matches[password_confirm]'
),
'password_confirm' => array(
'field' => 'password_confirm',
'rules' => 'trim|matches[password]'
)
);
This is my controller
function edit($id = NULL)
{
$id == NULL || $this->data['user'] = $this->user_m->get($id);
$rules = $this->user_m->rules_admin;
$id || $rules['password'] .= '|required'; // i have Noticed about this
$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == TRUE) {
}
$this->data['subview'] = 'components/admin_edit';
$this->load->view('components/index', $this->data);
}
public function _unique_email($str)
{
$id = $this->uri->segment(4);
$this->db->where('email', $this->input->post('email'));
!$id || $this->db->where('id !=', $id);
$user = $this->user_m->get();
if (count($user)) {
$this->form_validation->set_message('_unique_email', '%s should be unique');
return FALSE;
}
return TRUE;
}
I have loaded model, helper, library.
I also found 2 comments on video that provide solution, i try it but still not working.
What should i do? Thank you.
define $rules
as an array on top of the method
$rules = array();
$rules = $this->user_m->rules_admin;
or
$rules[] = $this->user_m->rules_admin;
No idea with what you trying to archive here $id || $rules['password'] .= '';
$id || $rules['password'] .= '';
If you need to push this to array you can use $rules['password'] = '|required';
(for password)
change
$id || $rules['password'] .= '|required';
to
$id || $rules['password']['rules'] .= '|required';
$rules['password']
is Array . Use String type .
Operator, return Notice Message: Array to string conversion
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.