https://github.com/remithomas/rt-object
Create an entity class to use mysql like NOSQL way.
https://github.com/remithomas/rt-object
Last synced: 12 months ago
JSON representation
Create an entity class to use mysql like NOSQL way.
- Host: GitHub
- URL: https://github.com/remithomas/rt-object
- Owner: remithomas
- Created: 2013-11-19T18:28:13.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-04-24T14:33:05.000Z (about 12 years ago)
- Last Synced: 2025-03-25T12:15:02.254Z (about 1 year ago)
- Language: PHP
- Size: 156 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
rt-object [](https://travis-ci.org/remithomas/rt-object)
==========
Create an entity class to use mysql like NOSQL way.
---------------------------------------
# Ask for contributions
Some ideas [to implement](https://github.com/remithomas/rt-object/pulls) to this useful code ? Or ups [some errors appear](https://github.com/remithomas/rt-object/issues)
---------------------------------------
# Requirements
* [Zend Framework 2](https://github.com/zendframework/zf2) (latest master)
* MySQL server
* [RtExtends](https://github.com/remithomas/rt-extends)
# Installation
---------------------------------------
## How to install ?
### Using composer.json
```json
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"minimum-stability": "dev",
"homepage": "http://framework.zend.com/",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "dev-master",
"remithomas/rt-object": "dev-master"
}
}
```
### Activate the module :
application.config.php
```php
array(
'Application',
'RtObject',
)
);
?>
```
### What's an object ?
An object is just 2 tables into your database:
* object
* object_data
### How to use it
#### Basic
Create a file Application\Entity\MyObject.php into *module/Application/src/Application/Entity*
```php
install();
// if you need extra columns to your object, add into your *module/Application/src/Application/Entity/MyObject.php* this code
public function install($extraColumnObject = array(), $extraColumnDataObject = array(), $extraTableObject = '', $extraTableDataObject = '') {
parent::install(array(
'extra_one' => "int(11) NOT NULL DEFAULT '1'",
'extra_two' => "varchar(512) CHARACTER SET utf8 NOT NULL",
));
}
// extra columns to object data
public function install($extraColumnObject = array(), $extraColumnDataObject = array(), $extraTableObject = '', $extraTableDataObject = '') {
parent::install(array(
'extra_one' => "int(11) NOT NULL DEFAULT '1'",
'extra_two' => "varchar(512) CHARACTER SET utf8 NOT NULL",
),
array(
'extra_one' => "int(11) NOT NULL DEFAULT '1'",
'extra_two' => "varchar(512) CHARACTER SET utf8 NOT NULL",
));
}
```
#### Create object
```php
$myObject = new \Application\Entity\MyObject();
$myObject->createObject();
$myObjectId = $myObject->getObjectId();
```
#### Get object
```php
$myObject = new \Application\Entity\MyObject();
$myObject ->setObjectId(1);
$myObjectInfo = $myObject->getObject();
```
#### Add data to object
```php
$myObject = new \Application\Entity\MyObject();
$myObject ->setObjectId(1);
->insertData("mycategory","mykey", "myvalue", "text");
// using extra column (to object data)
$myObject = new \Application\Entity\MyObject();
$myObject ->setObjectId(1);
->insertData("mycategory","mykey", "myvalue", "text", array("extra_one"=>1234));
```
#### Get object data
```php
$myObject = new \Application\Entity\MyObject();
$myObject ->setObjectId(1);
$myObjectData = $myObject->getObjectData();
// get some data
$myObjectData = $myObject->getObjectData("mycategory", "mykey");
```
#### Search object from value
```php
$myObject = new \Application\Entity\MyObject();
$aMyObjects = $myObject->searchValue("myvalue","text",100,0);// limit=100 && offset=0
```
#### object is existing
```php
$myObject = new \Application\Entity\MyObject();
$myObject ->setObjectId(1);
$bMyObject = $myObject->isExisting();
```
### Roadmap
* remove data from category
* some tools/javadoc
* PHPunit tests