PHP code example of nkizza / simplerelations

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

    

nkizza / simplerelations example snippets


class Match extends \yii\db\ActiveRecord
{
    public $_players;
	
    public function behaviors() {
        return [
            [
                'class' => \nkizza\simplerelations\RelatedBehavior::className(),
                'attribute' => '_players', //attribute which stores the related data
                'uploadRelation' => 'players', //relation name
                'uploadModelScenario' => 'default', //you can provide the specific scenario name for the related models
                'fields' => [   //fields of related record that we manage using this behavior
                    'id_player', 'min_played', 'goals', 'assists', 'y_cards', 'r_cards',            
                ],
            ],
        ];
    }
	
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['_players'], 'safe'],
        ];
    }
    
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPlayers()
    {
        return $this->hasMany(PlayerMatch::className(), ['id_match' => 'id']);
    }
    


use nkizza\simplerelations\RelationWidget;