PHP code example of wscore / datamapper

1. Go to this page and download the library: Download wscore/datamapper 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/ */

    

wscore / datamapper example snippets


namespace Tasks\Entity;

class Task extends EntityAbstract
{
    const STATUS_ACTIVE = '1';
    const STATUS_DONE   = '9';

    public static $_modelName = '\App\Tasks\Model\Tasks';
    public $task_id = null;
    public $memo = '';
    public $status = self::STATUS_ACTIVE;
}

class Tasks extends Model
{
    /** @var string     name of database table     */
    protected $table = 'task';

    /** @var string     name of primary key        */
    protected $id_name = 'task_id';

    public function __construct()
    {
        parent::__construct();
        $csv = file_get_contents( __DIR__ . '/tasks.csv' );
        $this->property->prepare( $csv );
    }
}

$task = $this->em->fetch( 'Tasks\Entity\Task' );
$role = $this->role->applyDataIO( $task );
$role->load( $_POST );
if( $role->validate() ) {
    $active = $this->role->applyActive( $role );
    $active->save();
}