我对 ION Auth 库有疑问。我想编辑现有组,当我尝试 dedit 时出现此错误:
错误在哪里,我探索了所有和 CI doc,但一切看起来都很好。
致命错误:在第 603 行的 /var/www/ci_balcanrent/beta/modules/user/controllers/user.php 中的非对象上调用成员函数 row()
这是编辑功能的控制器:
//edit a group
function edit_group($id) {
// bail if no group id given
if (!$id || empty($id)) {
redirect('user', 'refresh');
}
$this->data['title'] = $this->lang->line('edit_group_title');
if (!$this->ion_auth->logged_in() || !$this->ion_auth->is_admin()) {
redirect('user', 'refresh');
}
$group = $this->ion_auth->group($id)->row();
//validate form input
$this->form_validation->set_rules('group_name', $this->lang->line('edit_group_validation_name_label'), 'required|alpha_dash|xss_clean');
$this->form_validation->set_rules('group_description', $this->lang->line('edit_group_validation_desc_label'), 'xss_clean');
if (isset($_POST) && !empty($_POST)) {
if ($this->form_validation->run() === TRUE) {
$group_update = $this->ion_auth->update_group($id, $_POST['group_name'], $_POST['group_description']);
if ($group_update) {
$this->session->set_flashdata('success', $this->lang->line('edit_group_saved'));
} else {
$this->session->set_flashdata('error', $this->ion_auth->errors());
}
redirect("user", 'refresh');
}
}
//set the flash data error message if there is one
$this->data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('error')));
//pass the user to the view
$this->data['group'] = $group;
$this->data['group_name'] = array(
'name' => 'group_name',
'id' => 'group_name',
'type' => 'text',
'value' => $this->form_validation->set_value('group_name', $group->name),
);
$this->data['group_description'] = array(
'name' => 'group_description',
'id' => 'group_description',
'type' => 'text',
'value' => $this->form_validation->set_value('group_description', $group->description),
);
$this->template->build('auth/edit_group', $this->data);
}
603 行 $group = $this->ion_auth->group($id)->row();
模型 :
/**
* group
*
* @return object
* @author Ben Edmunds
**/
public function group($id = NULL)
{
$this->trigger_events('group');
if (isset($id))
{
$this->db->where($this->tables['groups'].'.id', $id);
}
$this->limit(1);
return $this->groups();
}
看法:
<?php echo form_open(current_url());?>
<p>
<?php echo lang('create_group_name_label', 'group_name');?> <br />
<?php echo form_input($group_name);?>
</p>
<p>
<?php echo lang('edit_group_desc_label', 'description');?> <br />
<?php echo form_input($group_description);?>
</p>
<p><?php echo form_submit('submit', lang('edit_group_submit_btn'));?></p>
<?php echo form_close();?>