Skip to content

Commit 1151ee7

Browse files
phinalavbdr
authored andcommitted
Add spaces after '#' (ThingEngineer#691)
So the Markdown compiler understands the titles.
1 parent faee21e commit 1151ee7

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

dbObject.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ dbObject - model implementation on top of the MysqliDb.
33
Please note that this library is not pretending to be a full stack ORM, but simply an OOP wrapper for `mysqlidb`.
44

55
<hr>
6-
###Initialization
6+
7+
### Initialization
78

89
Include mysqlidb and dbObject classes. If you want to use model autoloading instead of manually including them in the scripts use `autoload()` method.
910
```php
@@ -37,10 +38,10 @@ Both objects created throw new class file creation of with `table()` method will
3738
will not be working with an objects created with `table()` method.
3839

3940

40-
###Selects
41+
### Selects
4142
Retrieving objects from the database is pretty much the same process as a mysqliDb `get()`/`getOne()` methods without a need to specify table name. All mysqlidb functions like `where()`, `orWhere()`, `orderBy()`, `join()`, etc. are supported.
4243

43-
##Retrieving All Records
44+
## Retrieving All Records
4445

4546
```php
4647
//$users = dbObject::table('users')->get();
@@ -56,7 +57,7 @@ $users = user::where("login", "demo")->get(Array (10, 20));
5657
foreach ($users as $u) ...
5758
```
5859

59-
##Retrieving A Model By Primary Key
60+
## Retrieving A Model By Primary Key
6061

6162
```php
6263
//$user = dbObject::table('users')->byId(1);
@@ -71,7 +72,7 @@ dbObject will also assume that each table has a primary key column named "id". Y
7172
```
7273

7374

74-
###Insert Row
75+
### Insert Row
7576
1. OOP Way. Just create new object of a needed class, fill it in and call `save()` method. Save will return
7677
record id in case of success and false in case if insert will fail.
7778
```php
@@ -114,7 +115,7 @@ $p->save();
114115
After `save()` is called, both new objects (user and product) will be saved.
115116

116117

117-
###Update
118+
### Update
118119
To update model properties just set them and call `save()` method. Values that need to be changed could be passed as an array to the `save()` method as well.
119120

120121
```php
@@ -128,18 +129,18 @@ $user = user::byId(1);
128129
$user->save($data);
129130
```
130131

131-
###Delete
132+
### Delete
132133
Use `delete()` method on any loaded object.
133134
```php
134135
$user = user::byId(1);
135136
$user->delete();
136137
```
137138

138-
###Relations
139+
### Relations
139140
Currently dbObject supports only `hasMany` and `hasOne` relations. To use them declare `$relations` array in the model class.
140141
After that you can get related object via variable names defined as keys.
141142

142-
##hasOne example:
143+
## hasOne example:
143144
```php
144145
protected $relations = Array(
145146
'person' => Array("hasOne", "person", 'id');
@@ -163,7 +164,7 @@ To optimize this into single select join query use `with()` method.
163164
echo $user->person->firstName . " " . $user->person->lastName . " have the following products:\n";
164165
```
165166

166-
##hasMany example:
167+
## hasMany example:
167168
In the `hasMany` array should be defined the target object name (product in example) and a relation key (userid).
168169
```php
169170
protected $relations = Array(
@@ -190,15 +191,15 @@ First parameter will set an object which should be joined. Second paramter will
190191

191192
NOTE: Objects returned with `join()` will not save changes to a joined properties. For this you can use relationships.
192193

193-
###Timestamps
194+
### Timestamps
194195
Library provides a transparent way to set timestamps of an object creation and its modification:
195196
To enable that define `$timestamps` array as follows:
196197
```php
197198
protected $timestamps = Array ('createdAt', 'updatedAt');
198199
```
199200
Field names can't be changed.
200201

201-
###Array Fields
202+
### Array Fields
202203
dbObject can automatically handle array type of values. Optionaly you can store arrays in json encoded or in pipe delimited format.
203204
To enable automatic json serialization of the field define `$jsonFields` array in your modal:
204205
```php
@@ -221,7 +222,7 @@ Same with the `'sections'` variable except that it will be stored in pipe delimi
221222
print_r($user->options);
222223
```
223224

224-
###Validation and Error checking
225+
### Validation and Error checking
225226
Before saving and updating the row, dbObject does input validation. In case validation rules are set but their criteria is
226227
not met, then `save()` will return an error with its description. For example:
227228
```php
@@ -249,7 +250,7 @@ Second parameter is 'required' and its defines that following entry field be alw
249250

250251
**NOTE:** All variables which are not defined in the `$dbFields` array will be ignored from insert/update statement.
251252

252-
###Using array as a return value
253+
### Using array as a return value
253254
dbObject can return its data as array instead of object. To do that, the `ArrayBuilder()` function should be used in the beginning of the call.
254255
```php
255256
$user = user::ArrayBuilder()->byId(1);
@@ -266,12 +267,12 @@ The following call will return data only of the called instance without any rela
266267
print_r ($user['products']);
267268
```
268269

269-
###Using json as a return value
270+
### Using json as a return value
270271
Together with `ArrayBuilder()` and `ObjectBuilder()`, dbObject can also return a result in json format to avoid extra coding.
271272
```php
272273
$userjson = user::JsonBuilder()->with("product")->byId(1);
273274
```
274-
###Object serialization
275+
### Object serialization
275276

276277
Object could be easily converted to a json string or an array.
277278

@@ -285,7 +286,7 @@ Object could be easily converted to a json string or an array.
285286
$userArray = $user->toArray();
286287
```
287288

288-
###Pagination
289+
### Pagination
289290
Use paginate() instead of get() to fetch paginated result
290291
```php
291292
$page = 1;
@@ -296,7 +297,7 @@ echo "showing $page out of " . product::$totalPages;
296297

297298
```
298299

299-
###Hidden Fields
300+
### Hidden Fields
300301
Sometimes it's important to block some fields that can be accessed from outside the model class (for example, the user password).
301302

302303
To block the access to certain fields using the `->` operator, you can declare the `$hidden` array into the model class. This array holds column names that can't be accessed with the `->` operator.
@@ -331,6 +332,6 @@ $user->password = "my-new-password";
331332

332333
Won't change the current `password` value.
333334

334-
###Examples
335+
### Examples
335336

336337
Please look for a use examples in <a href='tests/dbObjectTests.php'>tests file</a> and test models inside the <a href='tests/models/'>test models</a> directory

0 commit comments

Comments
 (0)