Welcome Guest, Not a member yet? Register   Sign In
CRUD with Ci 1.7
#11

[eluser]umefarooq[/eluser]
i know that's not a library you can use as common model, using this you no need to write model again and again you can say its a common model for your all controllers. and you can modify your model from one location. for your need.
#12

[eluser]Colin Williams[/eluser]
But it's not a common model; not at all. It's just the database class with a new face.
#13

[eluser]umefarooq[/eluser]
what every you think its working good with my application everybody has his own logic. i just my experience with CI Community.
#14

[eluser]Colin Williams[/eluser]
Well, of course it works good. It literally just wraps a handful of database class functions.

Code:
/**
         * $table  database table name required.
         * $num optional using when pagination use
         * $offset optional using when pagination use.
         *
         */
        function getRecords($table,$num = '',$offset = ''){
        
            $query = $this->ci->db->get($table,$num,$offset);
            return $query->result();
        }

        /**
         * $table database table name required
         * $clause array of clauses is required
         */
    
        function getRecord($table,$clause=''){
        
            $query = $this->ci->db->get_where($table,$clause);
            return $query->row();
        }

        /**
         * $table database table name required
         * $data is array of data want to insert required
         */
    
        function setRecord($table,$data){
            $this->ci->db->insert($table,$data);
        }

        /**
         * $table database table name required
         * $data required to update recored
         * $clause array of clauses is required
         */
    
        function updateRecord($table,$data,$clause){
            return $this->ci->db->update($table,$data,$clause);
        }

        /**
         * $table database table name required
         * $clause array of clauses is required
         */
          
        function deleteRecord($table,$clause){
            $this->ci->db->delete($table,$clause);
        }

        /**
         * it will give you last inserted id.
         */
        
        function getLastID(){
            return $this->ci->db->insert_id();
        }

        /**
         * $table name is required to get row counts.
         */
    
        function getCount($table){
            return $this->ci->db->count_all($table);            
        }
        
    }
#15

[eluser]Xeoncross[/eluser]
This class is great for people that come from a camelCaseLanguage like Javascript and like to use hardToReadFunctionNames() instead of standard_php_functions(). Other than that you just added 25kb overhead (and a couple ms) for the privilege of breaking PHP guidelines AND wrapping around another object. Job well done.
#16

[eluser]Colin Williams[/eluser]
I was actually going to makeThisNewAPI evenMoreVerboseThanItHasAlreadyBeenMade and re-release it, but I think I'll pass.

Code:
$this->crudDatabaseAbstractedAbstractionLayer->getRowsInDatabaseWithTheseParameters();

... just having fun. Please don't take offense, anyone.
#17

[eluser]Colin Williams[/eluser]
But to get back to a serious discussion, I think the community could benefit from a solid CRUD/Scaffold application for CI. Scaffolding Part Deux.

I think where the deprecated scaffolding failed was that it wasn't implemented quite like a normal CI application (close, but no cigar.) So people couldn't really use it and look at the code and get a good idea of how they might construct their own application.

It's a missing feature that I think the community could provide while EllisLab works on cooler stuff.

.. I might even toy around with it today, see where it goes.
#18

[eluser]Xeoncross[/eluser]
I have made several attempts at good models for doing things in a database - only to find that everyone I make seems to end up taking just as much code to call the function - yet now I am also wasting space and time by adding more objects to my application load.

Just like you showed earlier Colin, I just can't seem to beat the one/two lines it takes to just use the AR CodeIgniter already provides.

Code:
$query = $this->db->get_where('mytable', array('id' => $id));
#19

[eluser]darkhouse[/eluser]
[quote author="Colin Williams" date="1234660019"]I was actually going to makeThisNewAPI evenMoreVerboseThanItHasAlreadyBeenMade and re-release it, but I think I'll pass.

Code:
$this->crudDatabaseAbstractedAbstractionLayer->getRowsInDatabaseWithTheseParameters();

... just having fun. Please don't take offense, anyone.[/quote]

LOL. I've been looking for something like this for a while... what would it take to get this in development?
#20

[eluser]Colin Williams[/eluser]
Well, here's how you "beat" it. Let's use a silly object, like a cat. When we want our cat model to give us a specific cat, we call something like

Code:
$this->cat_model->get('sir fluffington');

What you've taken out is the notion of a table, and even the notion of the structure of the table. You're just saying, "Get me Sir Fluffington." Or, more complex, what if you want to get cats from the current user.

Code:
$this->cat_model->get_user_cats($user_id);

From these two method calls, you can't really infer how the model gets that data. Is it coming from a database, an external API, a human-powered data-entry center, an automatic kitty vending machine? It's not for the Controller to really know or care. That's what the model is for.

And, there are ways to abstract it a little, at least if you limit yourself to using database storage. If you want to PM me, Xeoncross, anybody, I'd be happy to share some more about that.

Quote:LOL. I’ve been looking for something like this for a while… what would it take to get this in development?

Hrmm.. maybe we can just fork the whole framework to "CodeIgniterTheOpenSourcePHPFramework"




Theme © iAndrew 2016 - Forum software by © MyBB