Codeigniter row()在非对象上

时间:2013-08-05 13:34:05

标签: php codeigniter codeigniter-2

ION Auth库有问题。我想编辑现有的组,当我尝试dedit我有这个错误:

错误在哪里,我探索所有和CI文档,但一切看起来都很好。

  

致命错误:调用非对象中的成员函数row()   /var/www/ci_balcanrent/beta/modules/user/controllers/user.php在线   603

这是编辑功能的控制器:

   //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();?>

1 个答案:

答案 0 :(得分:0)

$group = $this->ion_auth->group($id)->row();

问题:

$this->ion_auth->group($id)返回group类对象。因此,您无法从row()类调用Datbase group方法。