1. Go to this page and download the library: Download ironbound/db 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/ */
$author = Author::get( 1 );
$author->user->display_name = 'John Doe'; // This is a WP_User object
$author->picture->post_title = 'John Doe'; // This is a WP_Post object
$author->save(); // The User and Post were automatically saved
// You can have WP objects inserted too
$author = new Author(
'picture' => new WP_Post( (object) array(
'post_type' => 'attachment',
'post_title' => 'Jane Doe'
) );
);
$author->save();
class Author extends \IronBound\DB\Model\ModelWithMeta {
public function get_pk() {
return $this->id;
}
protected function _books_relation() {
$relation = new HasMany( 'author', get_class( new Book() ), $this, 'books' );
$relation->keep_synced();
return $relation;
}
protected static function get_table() {
return static::$_db_manager->get( 'authors' );
}
public static function get_meta_table() {
return static::$_db_manager->get( 'authors-meta' );
}
}
class Authors extends \IronBound\DB\Table\BaseTable {
public function get_table_name( \wpdb $wpdb ) {
return "{$wpdb->prefix}authors";
}
public function get_slug() {
return 'authors';
}
public function get_columns() {
return array(
'id' => new \IronBound\DB\Table\Column\IntegerBased( 'BIGINT', 'id', array( 'unsigned', 'auto_increment' ), array( 20 ) ),
'name' => new \IronBound\DB\Table\Column\StringBased( 'VARCHAR', 'name', array(), array( 60 ) ),
'birth_date' => new \IronBound\DB\Table\Column\DateTime( 'birth_date' ),
'bio' => new \IronBound\DB\Table\Column\StringBased( 'LONGTEXT', 'bio' ),
'picture' => new \IronBound\DB\Table\Column\ForeignPost( 'picture', new \IronBound\DB\Saver\PostSaver() ),
'user' => new \IronBound\DB\Table\Column\ForeignUser( 'user', new \IronBound\DB\Saver\UserSaver() )
);
}
public function get_column_defaults() {
return array(
'id' => 0,
'name' => '',
'birth_date' => '',
'bio' => '',
'picture' => 0,
'user' => 0
);
}
public function get_primary_key() {
return 'id';
}
public function get_version() {
return 1;
}
}
\IronBound\DB\Manager::register( new Authors() );
\IronBound\DB\Manager::register( new BaseMetaTable( new Authors() ) );
\IronBound\DB\Manager::maybe_install_table( new Authors() );
\IronBound\DB\Manager::maybe_install_table( new BaseMetaTable( new Authors() ) );
class Authors extends \IronBound\DB\Table\BaseTable implements \IronBound\DB\Table\ForeignKey\DeleteConstrained {
// ... other methods
public function get_delete_constraints() {
return array(
'user' => self::RESTRICT // Exception thrown when deleting a User if an author referencing it exists,
'picture' => self::SET_DEFAULT // The column will be updated to its default value when its referenced post is deleted
);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.