PHP code example of mongosoft / yii2-xmlpipe

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

    

mongosoft / yii2-xmlpipe example snippets




namespace app\models;

use mongosoft\xmlpipe\BaseXmlPipe;

class XmlPipeDocument extends BaseXmlPipe
{
    /**
     * @inheritdoc
     */
    public function fields()
    {
        return [
            'name',
            'description',
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributes()
    {
        return [
            ['name' => 'type', 'type' => 'int', 'bits' => 16],
            ['name' => 'name', 'type' => 'string'],
            ['name' => 'description', 'type' => 'string'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function addDocuments()
    {
        $query = Items::find()
            ->select(['type', 'full_name', 'description'])
            ->asArray();

        foreach ($query->each() as $item) {
            $this->pushDocument([
                'type' => $item['type'],
                'name' => $item['full_name'],
                'description' => $item['description'],
            ]);
        }
    }
}



namespace app\controllers;

use yii\web\Controller;

class TestController extends Controller
{
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'xmlpipe' => [
                'class' => 'mongosoft\xmlpipe\Action',
                'document' => 'app\models\XmlPipeDocument',
            ],
        ];
    }
}

source myindex
{
    type               = xmlpipe2
    xmlpipe_command    = curl http://localhost/test/xmlpipe
}

index myindex
{
    source             = myindex
    path               = /var/path/to/index/myindex
    docinfo            = extern
    morphology         = lemmatize_ru
    charset_type       = utf-8
}