aboutsummaryrefslogtreecommitdiff
path: root/apps/web/third_party/ci-crud/README.md
blob: f6f7325033bcf9436e453d3dae759b4c40d421b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
ci-crud
=======

Ready to go, easy to use CodeIgniter Model for basic CRUD operations on a table


### Installation

Drop the files into the appropriate directory (same as what is in the repo's directory structure)

### Usage

Load the model using 

```
$this->load->model('CRUD_model', 'crud');
```

Given this table (which is an example)

```
CREATE TABLE `users` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `first_name` varchar(255) NOT NULL DEFAULT '',
    `last_name` varchar(255) NOT NULL DEFAULT '',
    `phone` varchar(25) DEFAULT NULL,
    `email` varchar(255) DEFAULT NULL,
    `created_on` datetime NOT NULL,
    `mod_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```


To create your data.  Pass in an array, and use your table field names as the array keys.

```
$data['first_name'] = 'Steve';
$data['last_name'] 	= 'Jobs';
$data['last_name'] 	= '408-555-1212';
$data['email'] 		= 'norelpy@apple.com';

$this->crud->table('users')->create($data);
```

To update your data.  In the data you pass to the method, use your table field names as the array key.

```
// this will update user with id 1, changing last name to 'Ives'
$id = 1;
$data['last_name'] = 'Ives';

$this->crud->table('users')->create($id, $data);
```

To retrive your data.  Pass in the ID of the entry you want, or don't pass an id and it will return all records.

```
$id = 1;
$record = $this->crud->table('users')->get($id);

var_dump($record);
```