PHP code example of pozitronik / yii2-searchwidget

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

    

pozitronik / yii2-searchwidget example snippets


...
'components' => [
    'searchWidget' => [
        'class' => SearchWidget::class,
        'models' => [
            'Users' => [
                'class' => Users::class
            ],
            ...
        ],
        ...
    ],
    ...

    SearchWidget::widget([
        'models' => [
            'Users' => [
                'class' => Users::class
            ],
            ...
        ]
]);

'components' => [
    'searchWidget' => [
        'class' => SearchWidget::class,
        'models' => [
            'Model1Alias' => [
                'class' => Model1::class
            ],
            'Model2Alias' => [
                'class' => Model2::class
            ],
            ...
        ]
    ]
    ...
]

...
'components' => [
    'searchWidget' => [
        'class' => SearchWidget::class,
        'ajaxEndpoint' => '/site/search',
        'models' => [
            'Users' => [
                'class' => Users::class,
                'template' => '<div class="suggestion-item"><div class="suggestion-name">{{name}}</div><div class="clearfix"></div><div class="suggestion-secondary">{{controller}}</div><div class="suggestion-links"><a href="'.Url::to('users/edit').'?id={{id}}" class="dashboard-button btn btn-xs btn-info pull-left">Edit<a/></div><div class="clearfix"></div></div>',
                'header' => 'Users',
                'limit' => 3,
                'attributes' => [
                    'username',
                    ['email', SearchWidget::SEARCH_TYPE_LIKE_BEGINNING]
                ]
            ],
            'Products' => [
                'class' => Products::class,
                'ajaxEndpoint' => '/products/search',
                'templateView' => '@app/views/products/search-template'
                'header' => 'Products',
                'limit' => null,
                'attributes' => [
                    'name',
                     ['code', SearchWidget::SEARCH_TYPE_EQUAL]
                ]
            ]
        ],
        ...
    ],
    ...

...
'components' => [
    'usersSearchWidget' => [
        'class' => SearchWidget::class,
        'models' => [
            'Users' => [
                'class' => Users::class,
            ]
        ],
    ],
    'productsSearchWidget' => [
        'class' => SearchWidget::class,
        'models' => [
            'Products' => [
                'class' => Products::class,
            ]
        ],
    ],

    SearchWidget::widget(['componentName' => 'usersSearchWidget']);//search only in users
    SearchWidget::widget(['componentName' => 'productsSearchWidget']);//search only in products

php composer.phar