Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
PHP-MySQLi-Database-Class
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
PHP-MySQLi-Database-Class
Commits
6a3e2477
Commit
6a3e2477
authored
Jul 07, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dbObject: added JsonBuilder()
parent
cf5fd70b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
dbObject.md
dbObject.md
+7
-2
dbObject.php
dbObject.php
+15
-0
No files found.
dbObject.md
View file @
6a3e2477
...
...
@@ -239,7 +239,7 @@ Second parameter is 'required' and its defines that following entry field be alw
NOTE: All variables which are not defined in the $dbFields array will be ignored from insert/update statement.
###
Array as return values
###
Using array as a return value
dbObject can return its data as array instead of object. To do that ArrayBuilder() function should be used in the beginning of the call.
```
php
$user
=
user
::
ArrayBuilder
()
->
byId
(
1
);
...
...
@@ -251,11 +251,16 @@ dbObject can return its data as array instead of object. To do that ArrayBuilder
```
Following call will return data only of the called instance without any relations data. Use with() function to include relation data as well.
```
php
$user
=
user
::
ArrayBuilder
()
->
with
(
"product"
)
->
byId
(
1
);
print_r
(
$user
[
'products'
]);
```
###Using json as a return value
Togeather with ArrayBuilder() and ObjectBuilder() dbObject can return result in json format to avoid extra coding
```
php
$userjson
=
user
::
JsonBuilder
()
->
with
(
"product"
)
->
byId
(
1
);
```
###Object serialization
Object could be easily converted to a json string or an array.
...
...
dbObject.php
View file @
6a3e2477
...
...
@@ -170,6 +170,16 @@ class dbObject {
unset
(
$this
->
data
[
$name
]);
}
/**
* Helper function to create dbObject with Json return type
*
* @return dbObject
*/
public
static
function
JsonBuilder
()
{
$obj
=
new
static
;
$obj
->
returnType
=
'Json'
;
return
$obj
;
}
/**
* Helper function to create dbObject with Array return type
...
...
@@ -299,6 +309,8 @@ class dbObject {
$this
->
processArrays
(
$results
);
$this
->
data
=
$results
;
$this
->
processWith
(
$results
);
if
(
$this
->
returnType
==
'Json'
)
return
json_encode
(
$results
);
if
(
$this
->
returnType
==
'Array'
)
return
$results
;
...
...
@@ -334,6 +346,9 @@ class dbObject {
if
(
$this
->
returnType
==
'Object'
)
return
$objects
;
if
(
$this
->
returnType
==
'Json'
)
return
json_encode
(
$results
);
return
$results
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment