PHPackages                             samsonos/cms\_search - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. samsonos/cms\_search

ActiveLibrary[Search &amp; Filtering](/categories/search)

samsonos/cms\_search
====================

2992PHP

Since Feb 10Pushed 11y ago3 watchersCompare

[ Source](https://github.com/samsonos/cms_search)[ Packagist](https://packagist.org/packages/samsonos/cms_search)[ RSS](/packages/samsonos-cms-search/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Material searcher for [SamsonPHP](http://samsonphp.com) framework
=================================================================

[](#material-searcher-for-samsonphp-framework)

If you want to find some materials for a given key - the fastest way is to use class CMSSearch

Construct parameters
--------------------

[](#construct-parameters)

In CMSSearch constructor you must define at least 2 first parameters

- **$searchKey** – required Value for searching
- **$searchFields** – required Array of identifiers from table field for searching
- **$getParams** – Url GET parameters
- **$itemsOnPage** – Count of objects on one page for php\_pager
- **$pagerPrefix** – Prefix in pager links url
- **$handler** – External handler for editing query

Example
-------

[](#example)

For example if you want to find some materials with key 'first' and create search in fields with identifiers 5, 2 and 7, you can use follow code

PHP code:

```
// Define fields array
$fields = array(5, 2, 7);
// Create search object
$search = new samsonos\cms\search\CMSSearch('first', $fields, array('key'=>$search));

// Create view of founded objects
$materialHTML = '';
foreach ($search->searchMaterials() as $product) {
	$materialHTML .= m()->view('search/item')->product($product)->output();
}
$searchBlock = m()->view('search/items')
	->set($search->pager)
	->searchItems($materialHTML)
	->output();
```

Crete simple preview of founded items
-------------------------------------

[](#crete-simple-preview-of-founded-items)

Thanks to CMSSearch module you can create a simple preview using your own async controller that must be defined in attribute 'preview-action' of search input. For using that you need add class 'samson\_CMS\_searchInput' to your search input. If you want to show loader while you are waiting for ajax response, you can add block with class samson\_CMS\_searchLoader to your html code.

Preview Example
---------------

[](#preview-example)

HTML code:

```
