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

[eluser]Omarion[/eluser]
Hi all,

Somebody know some crud that works with CI 1.7?

I tried the Code Crafter but I can't. There's some contants that dont exists n the CI 1.7.

Thanks!
#2

[eluser]umefarooq[/eluser]
try to make your own its better to handle in future also, if you don't want try to search in wiki you will find some good libraries for CRUD there

http://codeigniter.com/wiki/
#3

[eluser]Omarion[/eluser]
Hi umefarooq, thanks!

So, I intend to make a simple, but generic CRUD.
Somebody already has to used some library for to do it?

Thanks!
#4

[eluser]Omarion[/eluser]
anyone?
#5

[eluser]darkhouse[/eluser]
I saw someone on here create a Base_model which has the generic CRUD methods, and then each new model extends the Base_model. You just need to autoload the Base_model I believe.
#6

[eluser]umefarooq[/eluser]
hi omrion here is simple CRUD for you and whole CI Community.

Simple CRUD

here how to use it

1. first call crud library controller's constructor or any specific function of controller.
Code:
$this->load->library('crud');

2. here is insert,update and delete using library

in insert you have to pass table name and array of data to insert.
Code:
$data = array('name'=>$name,'description'=>$desc);
$this->crud->setRecord('test',$data);

in update record you have to pass table name, array of data and selector of specific data
Code:
$this->crud->updateRecord('test',$data,array('id'=>$id));

in delete record you have pass table name and selector of specific data
Code:
$this->crud->deleteRecord('test',array('id'=>$id));

to get specific record, it will return you only one row by passing table name and selector.
Code:
$row = $this->crud->getRecord('test',array('id'=>$id));

to get all rows just pass table name,
Code:
$data['rows'] = $this->crud->getRecords('test');

and when using pagination pass record per page and page number to the getRecords function as
Code:
$data['rows'] = $this->crud->getRecords('test',20,1);

to get the count of all rows pass only table name
Code:
$this->crud->getCount('test');

to get last inserted id
Code:
$this->crud->getLastID('test');


this CRUD library is generic library no need to code models again and again you can modify library according to your need. please report me bugs and updates about this library.
#7

[eluser]pistolPete[/eluser]
@umefarooq: Some suggestions:

If you want to use the class in PHP4, there is a problem with calling get_instance() from within the class constructors.
Have a look at:
- Utilizing CodeIgniter Resources within Your Library
- Bug Report

I'd rather use NULL as the default value of some parameters as it is NULL as well in the CI_DB_active_record class; e.g.:
Code:
function getRecords($table, $num = NULL, $offset = NULL)

Add an instance variable $table to the class and pass it to the constructor and / or provide a method setTable($tableName), so you don't have to pass the table name everytime you want to call a single function.
#8

[eluser]umefarooq[/eluser]
so any solution to use get_instance() in PHP4 so this library will work with php4 also. i use common table name for example, in same controller you can use multiple tables also for that no need to set every time table name its better to pass to specific function.
#9

[eluser]pistolPete[/eluser]
[quote author="umefarooq" date="1234567958"]so any solution to use get_instance() in PHP4 so this library will work with php4 also.[/quote]
There is a good example in ./system/codeigniter/Base4.php.

[quote author="umefarooq" date="1234567958"]i use common table name for example, in same controller you can use multiple tables also for that no need to set every time table name its better to pass to specific function.[/quote]
Setting the table name once for every model increases portability and lets you change e.g. your table name easily, you just have to change one name instead of multiple occurences.
#10

[eluser]Colin Williams[/eluser]
Is that seriously a library, umefarooq? Looks eerily familiar....

Code:
$data = array('name'=>$name,'description'=>$desc);
$this->crud->setRecord('test',$data);

// Same as

$data = array('name'=>$name,'description'=>$desc);
$this->db->insert('test', $data);

Code:
$this->crud->updateRecord('test',$data,array('id'=>$id));

// Same as

$this->db->update('test', $data, array('id'=>$id));

Code:
$this->crud->deleteRecord('test',array('id'=>$id));

// Same as

$this->db->delete('test', array('id'=>$id));

Code:
$row = $this->crud->getRecord('test',array('id'=>$id));

// Same as

$row = $this->db->get_where('test', array('id'=>$id))->row();

... See where I'm getting at. It provides no new functionality! It's just a more verbose version of ActiveRecord. I can't believe someone really wrote that...

And...

Quote:i use common table name for example, in same controller you can use multiple tables also for that no need to set every time table name its better to pass to specific function.

The controller should have absolutely no clue how or where data is stored (it just knows that the model does it). This is the whole point of models.




Theme © iAndrew 2016 - Forum software by © MyBB