Também uso algo parecido, mas sempre retornando TRUE ou FALSE. Veja a função de 
excluir:

    public function delete($table, $id)
    {
        $this->db->delete($table, array('id' => $id) );
        
        return (bool) $this->db->affected_rows();
    }

 Att
Jônatan Fróes - Desenvolvedor web
http://twitter.com/jonatanfroes




________________________________
De: "[email protected]" <[email protected]>
Para: [email protected]
Enviadas: Terça-feira, 29 de Junho de 2010 6:37:05
Assunto: Digest Lista, volume 35, assunto 43

Enviar submissões para a lista de discussão Lista para 
    [email protected]

Para se cadastrar ou descadastrar via WWW, visite o endereço
    http://codeigniter.com.br/mailman/listinfo/lista_codeigniter.com.br
ou, via email, envie uma mensagem com a palavra 'help' no assunto ou
corpo da mensagem para 
    [email protected]

Você poderá entrar em contato com a pessoa que gerencia a lista pelo
endereço
    [email protected]

Quando responder, por favor edite sua linha Assunto assim ela será
mais específica que "Re: Contents of Lista digest..."


Tópicos de Hoje:

   1. CRUD generico (Cliff Oliveira)
   2. Re: CRUD generico (Vinicius Cruz)
   3. RES:  CRUD generico (Rafael V. de Oliveira)


----------------------------------------------------------------------

Message: 1
Date: Mon, 28 Jun 2010 20:50:43 -0300
From: Cliff Oliveira <[email protected]>
To: CodeIgniter Brasil <[email protected]>
Subject: [CodeIgniter] CRUD generico
Message-ID:
    <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Saudaçoes

a lista já me ajudou muito, por isso posto aqui um CRUD genérico que usamos
aqui na Tribo
ele tem me ajudado em muita coisa e espero que seja útil tbm a alguém :

<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class crud_model extends Model {
    function _construct() {
        parent::Model();
        $this->load->database();
    }
    function inserir($table, $array) {
        $this->db->insert($table, $array);
        return true;
    }
    function atualizar($table, $id_name, $array) {
        $this->db->where($id_name,$array[$id_name]);
        $this->db->update($table, $array);
        return true;
    }
    function deletar($table, $id_name, $array) {
        $this->db->where($id_name,$array[$id_name]);
        $this->db->delete($table);
        return true;
    }
    function mostrar($table) {
        $query = $this->db->get($table);
        return $query;
    }
    function mostrar_onde($table, $array) {
        $query = $this->db->get_where($table, $array);
        return $query;
    }

    function mostrar_ordenado($table, $array, $col, $how) {
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where($array);
        $this->db->order_by($col, $how);
        $query = $this->db->get();
        return $query;
    }


}
?>


-- 
Cliff Oliveira
www.tribodeideias.com.br
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: 
<http://codeigniter.com.br/pipermail/lista_codeigniter.com.br/attachments/20100628/91984c4c/attachment-0001.html>

------------------------------

Message: 2
Date: Mon, 28 Jun 2010 21:14:29 -0300
From: Vinicius Cruz <[email protected]>
To: CodeIgniter Brasil <[email protected]>
Subject: Re: [CodeIgniter] CRUD generico
Message-ID:
    <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Legal a iniciativa, Cliff.

Mas uma dica: em caso de houver falha ao inserir registro no banco, sempre
terei TRUE como retorno?! :-)
A idéia é sempre aprimorar a classe.

Abraço!

Att,
Vinicius Cruz
http://twitter.com/vinaocruz
http://www.viniciuscruz.com/


Em 28 de junho de 2010 20:50, Cliff Oliveira <[email protected]>escreveu:

> Saudaçoes
>
> a lista já me ajudou muito, por isso posto aqui um CRUD genérico que usamos
> aqui na Tribo
> ele tem me ajudado em muita coisa e espero que seja útil tbm a alguém :
>
> <?php
> /*
>  * To change this template, choose Tools | Templates
>  * and open the template in the editor.
> */
> class crud_model extends Model {
>     function _construct() {
>         parent::Model();
>         $this->load->database();
>     }
>     function inserir($table, $array) {
>         $this->db->insert($table, $array);
>         return true;
>     }
>     function atualizar($table, $id_name, $array) {
>         $this->db->where($id_name,$array[$id_name]);
>         $this->db->update($table, $array);
>         return true;
>     }
>     function deletar($table, $id_name, $array) {
>         $this->db->where($id_name,$array[$id_name]);
>         $this->db->delete($table);
>         return true;
>     }
>     function mostrar($table) {
>         $query = $this->db->get($table);
>         return $query;
>     }
>     function mostrar_onde($table, $array) {
>         $query = $this->db->get_where($table, $array);
>         return $query;
>     }
>
>     function mostrar_ordenado($table, $array, $col, $how) {
>         $this->db->select('*');
>         $this->db->from($table);
>         $this->db->where($array);
>         $this->db->order_by($col, $how);
>         $query = $this->db->get();
>         return $query;
>     }
>
>
> }
> ?>
>
>
> --
> Cliff Oliveira
> www.tribodeideias.com.br
>
> _______________________________________________
> Lista mailing list
> [email protected]
> http://codeigniter.com.br/mailman/listinfo/lista_codeigniter.com.br
>
>
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: 
<http://codeigniter.com.br/pipermail/lista_codeigniter.com.br/attachments/20100628/13867a57/attachment-0001.html>

------------------------------

Message: 3
Date: Tue, 29 Jun 2010 10:36:53 +0100
From: "Rafael V. de Oliveira" <[email protected]>
To: "'CodeIgniter Brasil'" <[email protected]>
Subject: [CodeIgniter] RES:  CRUD generico
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

É tão bom saber que faço parecido com os bons :P



Só faço um pouco diferente, e acho legal partilhar convosco.



A tabela é sempre definida para a classe toda



protected $table = ‘’;



function __construct()

{

                $this->table =
$this->config->item(‘prefixo_das_tabelas’).’nome_da_tabela’;

}



Eu tenho uma function para fazer where



private function get_where( $where = array() )

{

                $this->db->where($where);

}



Assim sendo, eu não preciso de 2 functions para mostrar e mostrar_onde.

Fica uma só, assim



protected function mostrar( $where = FALSE )

{

                if ( $where !== FALSE )

                               $this->get_where( $where );

                //Andamento com a situation

                

                return $this->db->get($this->table);

}



Quanto as functions de manipulação, eu tento sempre retornar com o
affected_rows() ou insert_id();

Assim eu tenho certeza que a operação ocorreu certo. Ou errado :P



Mas de resto, é tal qual.



Abraços



De: [email protected]
[mailto:[email protected]] Em nome de Cliff Oliveira
Enviada em: terça-feira, 29 de junho de 2010 00:51
Para: CodeIgniter Brasil
Assunto: [CodeIgniter] CRUD generico



Saudaçoes

a lista já me ajudou muito, por isso posto aqui um CRUD genérico que usamos
aqui na Tribo
ele tem me ajudado em muita coisa e espero que seja útil tbm a alguém :

<?php
/* 
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class crud_model extends Model {
    function _construct() {
        parent::Model();
        $this->load->database();
    }
    function inserir($table, $array) {
        $this->db->insert($table, $array);
        return true;
    }
    function atualizar($table, $id_name, $array) {
        $this->db->where($id_name,$array[$id_name]);
        $this->db->update($table, $array);
        return true;
    }
    function deletar($table, $id_name, $array) {
        $this->db->where($id_name,$array[$id_name]);
        $this->db->delete($table);
        return true;
    }
    function mostrar($table) {
        $query = $this->db->get($table);
        return $query;
    }
    function mostrar_onde($table, $array) {
        $query = $this->db->get_where($table, $array);
        return $query;
    }

    function mostrar_ordenado($table, $array, $col, $how) {
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where($array);
        $this->db->order_by($col, $how);
        $query = $this->db->get();
        return $query;
    }


}
?>


-- 
Cliff Oliveira
www.tribodeideias.com.br

-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: 
<http://codeigniter.com.br/pipermail/lista_codeigniter.com.br/attachments/20100629/15da9ea6/attachment.html>

------------------------------

_______________________________________________
Lista mailing list
[email protected]
http://codeigniter.com.br/mailman/listinfo/lista_codeigniter.com.br


Fim da Digest Lista, volume 35, assunto 43
******************************************



      
_______________________________________________
Lista mailing list
[email protected]
http://codeigniter.com.br/mailman/listinfo/lista_codeigniter.com.br

Responder a