Download the PHP package carlosmaiello/search without Composer
On this page you can find all versions of the php package carlosmaiello/search. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download carlosmaiello/search
More information about carlosmaiello/search
Files in carlosmaiello/search
Package search
Short Description CakePHP 3.0 easy search framework
License MIT
Homepage https://github.com/FriendsOfCake/search
Informations about the package search
CakePHP Search
Search provides a search module for CakePHP applications.
Requirements
The master branch has the following requirements:
- CakePHP 3.0.0 or greater.
Installation
-
Install the plugin with composer from your CakePHP Project's ROOT directory (where composer.json file is located)
- Load the plugin by adding following to your
config/bootstrap.php
or running command
Usage
The plugin has three main parts which you will need to configure and include in your application.
Table class
There are three tasks during setup in your table class. Firstly you must add a
use
statement for the Search\Manager
. Next you need to attach the Search
behaviour to your table class. Lastly you must add a searchConfiguration
method to your table class so that you can configure how the search will work.
Controller class
In order for the Search plugin to work it will need to process the query params
which are passed in your url. So you will need to edit your index
method to
accomodate this.
The search
finder and the filterParams()
method are dynamically provided by
the Search
behavior.
Component
Then add the Search Prg component to the necessary methods in your controller.
:warning: Make sure,
- That you add this in the controller's
initialize()
method. - That you only add this to methods which are using search, such as your
index()
method.
The Search.Prg
component will allow your filtering forms to be populated using
the data in the query params. It uses the Post, redirect, get pattern.
Filtering your data
Once you have completed all the setup you can now filter your data by passing
query params in your index method. Using the Article
example given above, you
could filter your articles using the following.
example.com/articles?q=cakephp
Would filter your list of articles to any article with "cakephp" in the title
or content
field. You might choose to make a get
form which posts the filter
directly to the url, but if you're using the Search.Prg
component, you'll want
to use POST
.
Creating your form
In most cases you'll want to add a form to your index view which will search your data.
If you are using the Search.Prg
component the forms current values will be
populated from the query params.
Filters
The Search plugin comes with a set of predefined search filters that allow you to easily create the search results you need. Use:
value
to limit results to exact matcheslike
to produce results containing the search query (LIKE
)finder
to produce results using a (custom) findercompare
to produce results requiring operator comparison (>
,<
,>=
and<=
)callback
to produce results using your own custom callable function
Optional fields
Sometimes you might want to search your data based on two of three inputs in
your form. You can use the filterEmpty
search option to ignore any empty fields.
Be sure to allow empty in your search form, if you're using one.