1. Go to this page and download the library: Download rjjakes/wordpress-orm library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rjjakes / wordpress-orm example snippets
namespace App\Models;
use Symlink\ORM\Models\BaseModel as Model;
/**
* @ORM_Type Entity
* @ORM_Table "product"
* @ORM_AllowSchemaUpdate True
*/
class Product extends Model {
/**
* @ORM_Column_Type TEXT
*/
protected $title;
/**
* @ORM_Column_Type datetime
*/
protected $time;
/**
* @ORM_Column_Type smallint
* @ORM_Column_Length 5
* @ORM_Column_Null NOT NULL
*/
protected $views;
/**
* @ORM_Column_Type varchar
* @ORM_Column_Length 32
* @ORM_Column_Null NOT NULL
*/
protected $short_name;
}
$orm = Manager::getManager();
$repository = $orm->getRepository(Product::class);
$product = $repository->find(9); // Load an object by known ID=9
$product->set('title', 'TITLE HAS CHANGED!');
$orm->flush();
$orm = Manager::getManager();
$repository = $orm->getRepository(Product::class);
$product = $repository->find(9); // Load an object by known ID=9
$orm->remove($product); // Queue up the object to be removed from the database.
$orm->flush();
use Symlink\ORM\Mapping;
$mapper = Mapping::getMapper();
$mapper->dropTable(Product::class);
try {
$query = $repository->createQueryBuilder()
->where('ID', 3, '==') // Equals operator should be '=' not '=='
->buildQuery();
} catch (\Symlink\ORM\Exceptions\InvalidOperatorException $e) {
// ... warn the user about the bad operator or handle it another way.
}