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.
#2

[eluser]minimalistic[/eluser]
Great work man.

I've started to use your crud maker and I'm loving it. I'll come back with a complete feedback later on.


Vx

CI Community - Brazil/Portugal
http://www.codeigniter.com.br
#3

[eluser]clip[/eluser]
version 0.1.1

Bugfix:

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. Setting the property of the primary_key field will now return query->row() and when it is not set, query->result() will be returned regardless of how many rows are returned.
#4

[eluser]clip[/eluser]
This is project is now hosted at Git

I have changed how the field names were collected. Prior version was using a deprecated function.

You can grab the latest source here
#5

[eluser]clip[/eluser]
I have just commit v0.1.3 to github. Added the ability to call multiple table joins. Example below.
Code:
$this->load->model('posts_model');
$post = new $this->posts_model();
$post->order_by = 'post_date DESC';

//array('table_to_be_joined'=>array('main_table_field', 'join_table_field', 'join_type'))

//if the join_type is omitted the default is a LEFT join

//you can also do multiple joins as you can see in this example

$post->join = array('categories'=>array('cat_id', 'id', 'LEFT'),
                    'users'=>array('author_id', 'id')
                    );

$posts = $post->get();

Get the new version from here.
#6

[eluser]clip[/eluser]
I have added some documentation @ github explaining the methods and properties available for the models generated by flaming-crud.
#7

[eluser]clip[/eluser]
Version 0.1.4 now available at github. Please see the Change Log and Docs for changes.




Theme © iAndrew 2016 - Forum software by © MyBB