PHP code example of riesenia / persist-related-data

1. Go to this page and download the library: Download riesenia/persist-related-data 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/ */

    

riesenia / persist-related-data example snippets


Plugin::load('PersistRelatedData');

class InvoicesTable extends Table
{
    public function initialize(array $config)
    {
        parent::initialize($config);

        // add PersistRelatedData behavior
        $this->addBehavior('PersistRelatedData.PersistRelatedData', [
            'fields' => [
                'contact_name' => 'Contacts.name',
                'contact_address' => 'Contacts.address'
            ]
        ]);

        // associations
        $this->belongsTo('Contacts', [
            'foreignKey' => 'contact_id',
            'className' => 'Contacts'
        ]);
    }
}