Error Calling a member function row () on a non-object Codeigniter

0

Password change screen, form is ok, but the variable to fetch the information in the bd giving error, in the row () function!

Follow VIEW:

case 'alterar_senha':
        $iduser= $this->uri->segment(3);
        if($iduser=NULL):
          set_msg('msgerro', 'Escolha um usuário para alterar', 'erro');
          redirect('usuarios/gerenciar');
        endif; ?>
        <div class="large-12 columns">
            <?php if (is_admin() || $iduser == $this->session->userdata('user_id')):
                $query = $this->usuarios->get_byid($iduser)->row();
                erros_validacao();
                get_msg('msgok');
                echo form_open(current_url(), array('class'=>'custom'));
                echo form_fieldset('Alterar Senha');
                echo '<div class="large-7 columns">';
                echo form_label('Nome completo');
                echo form_input(array('name'=>'nome', 'disabled'=>'disabled'), set_value('nome', $query->nome));
                echo form_label('Email');
                echo form_input(array('name'=>'email', 'disabled'=>'disabled'), set_value('email', $query->email));
                echo '<div class="large-7 columns>"';
                echo form_label('Login');
                echo form_input(array('name'=>'login',  'disabled'=>'disabled'), set_value('login', $query->login));
                echo form_label('Nova Senha');
                echo form_password(array('name'=>'senha'), set_value('senha'), 'autofocus');
                echo form_label('Repita a senha');
                echo form_password(array('name'=>'senha2'), set_value('senha2'));
                echo anchor('usuarios/gerenciar', 'Cancelar', array('class'=> 'button radius alert espaco'));
                echo form_submit(array('name'=>'alterarsenha', 'class'=>'button radius '), 'Salvar dados');
                echo form_hidden('idusuario', $iduser);
                echo form_fieldset_close();
                echo form_close();
            else:
                redirect('usuarios/gerenciar');
            endif;  ?>
        </div>

        <?php
        break;

Follow CONTROLLER with function:

public function alterar_senha(){
    esta_logado();
    set_tema('titulo','Alteração de senha');
    set_tema('conteudo',load_modulo('usuarios','alterar_senha'));
    load_template();
}

Follow MODEL:

public function get_byid($id=NULL) {
        if ($id != NULL):
            $this->db->where('id', $id);
            $this->db->limit(1);
            return $this->db->get('usuarios');
         else:
            return FALSE;   
         endif;
    }
    
asked by anonymous 05.11.2015 / 12:45

2 answers

0

This happens because the get_byid function does not return a objeto at some point, but a FALSE . This probably causes an error.

Instead, if no result is returned you should throw a Exception within get_byid .

I notice that there is a design error in your code. You should define the data you will use in the view in the controller, and not query the view.

So, keeping the current code in the 'Controller, you should do the following verification:

$query = $this->usuarios->get_byid($iduser);

if ($query !== FALSE) {
    $usuario = $query->row();
}
    
05.11.2015 / 13:10
0

Wallace, man, I found the error, it's part of the first if , it's missing a "%" sign ... if($iduser=NULL): , I put it and it worked normal! Thanks for the help!

    
05.11.2015 / 19:17