PHP code example of nikserg / yii2-xml-model-behavior

1. Go to this page and download the library: Download nikserg/yii2-xml-model-behavior 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/ */

    

nikserg / yii2-xml-model-behavior example snippets


use Document;
use nikserg\yii2\XmlModelBehavior\XmlArrayableTrait;
use nikserg\yii2\XmlModelBehavior\XmlModelBehavior;
use yii\base\Model;
class File extends Model
{
    use XmlArrayableTrait;
    
    public $idFile = null;
    public $applicationVersion = null;
    public $formVersion = null;

    /**
     * 
     * @property Document $document
     */
    public $document = null;

    public function behaviors()
    {
        $return = parent::behaviors();
        $return[] = [
            'class'       => XmlModelBehavior::class,
            'rootElement' => 'File',
        ];
        return $return;
    }

    public function fields()
    {
        return [
            '_idFile'   => 'idFile',
            '_applicationVersion' => 'applicationVersion',
            '_formVersion' => 'formVersion',
            'document'  => 'document',
        ];
    }
}

class Document extends Model
{
    use XmlArrayableTrait;
    public $documentId = null;

    public function fields()
    {
        return [
            '_id'   => 'documentId',
        ];
    }
}