Welcome Guest, Not a member yet? Register   Sign In
Flaming-Crud: Another CRUD Generator
#1

[eluser]clip[/eluser]
Firstly I would like to thank dixcoder for the inspiration from his Model/Controller Generator

I had also been contemplating throwing something like this together and now that I have done it, I wish I would have done it along time ago. The focus of Flaming-Crud is currently on models only. I have created and successfully used two different models with it now without issue. These were done on my local environment but I don't see why it would work on your host.

Here is a quick run down:
Quote:Download and unzip the ci_crud.php file and upload to your server.
Navigate to http://www.yourserver.com/ci_crud.php.
Fill out the form and submit it. Note: the Model Name field should be typed in all lowercase and not contain an extension.
Once you submit the form you should receive a confirmation and location of the file. Copy/Move this file to your models directory.

Latest Version: 0.1.3
Where do I git it? You can git it from here.

Model Structure:
The generated model will have a property created for each field from the db table along with $limit, $offset, and $order_by properties.

Code:
public $id; //in this example $id is the primary key from our table.
public $category_id;
//.....
public $limit;
public $offset;
public $order_by;
public $join;

//methods
get()
save()
delete()
count_recs()

Usage:
Code:
class Some_controller extends Controller
{
     function __construct()
     {
          parent::__construct();
          $this->load->model('your_model');
     }

     function index()
     {
          $obj = new $this->your_model();
          //to get all records we just call the get() method without setting any properties
          $items = $obj->get();
          //to get by id you would do:
          $obj->id = 5;
          //if you set the primary_key property the get() method will
          //return the $query->row() object.  All other get() calls w/out the primary_key
          //property being set will return the $query->result() object
          $item = $obj->get();
     }

     function edit()
     {
          $obj = new $this->your_model();
          //if we set the primary_key property the model will attempt to update an
          //existing record.  Not setting this property the model will insert a new record.
          $obj->id = 5;
          //set the properties doesn't have to be all of them just the ones you need.
          $obj->first_name = 'John';
          $obj->last_name = 'Dohdoh';
          //call the save() method
          $obj->save();
     }
}

Enjoy! Would love to here any feedback anyone may have.

Edit: I have made a minor change to how the code is output for returning query->result() and query->row(). Before this change a return of query->result() may have been expected but query->row() was returned instead.


Messages In This Thread
Flaming-Crud: Another CRUD Generator - by El Forum - 10-29-2009, 11:38 PM
Flaming-Crud: Another CRUD Generator - by El Forum - 10-30-2009, 04:12 AM
Flaming-Crud: Another CRUD Generator - by El Forum - 10-30-2009, 09:21 PM
Flaming-Crud: Another CRUD Generator - by El Forum - 11-01-2009, 10:25 PM
Flaming-Crud: Another CRUD Generator - by El Forum - 11-03-2009, 07:20 PM
Flaming-Crud: Another CRUD Generator - by El Forum - 11-05-2009, 02:09 PM
Flaming-Crud: Another CRUD Generator - by El Forum - 11-11-2009, 07:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB