Prismic.io PHP kit  3.0.0
Public Member Functions | List of all members
Prismic\SearchForm Class Reference

Public Member Functions

 __construct (Api $api, Form $form, array $data)
 
 getData ()
 
 ref ($ref)
 
 after ($documentId)
 
 fetch ()
 
 fetchLinks ()
 
 pageSize ($pageSize)
 
 page ($page)
 
 orderings ()
 
 submit ()
 
 count ()
 
 query ()
 
 url ()
 
 isCached ()
 

Detailed Description

Embodies an API call we are in the process of building. This gets started with Prismic\Api.form, then you can chain instance method calls to build your query, and the query gets launched with Prismic\SearchForm.submit.

For instance, here's how you query all of the repository: $result = $api->form('everything')->ref($ref)->submit()

And here's an example of a more complex query: $result = $api->form('products')->query('[[:d = any(document.tags, ["Featured"])]]')->pageSize(10)->page(2)->ref($ref)->submit()

Note that setting the ref is mandatory, or your submit call will fail.

Note also that SearchForm objects are immutable; the chainable methods all return new SearchForm objects.

Constructor & Destructor Documentation

§ __construct()

Prismic\SearchForm::__construct ( Api  $api,
Form  $form,
array  $data 
)

Constructs a SearchForm object

Parameters
Prismic::Api$apithe API object containing all the information to know where to query
Prismic::Form$formthe REST form we're querying on in the API
array$datathe parameters we're getting ready to submit

Member Function Documentation

§ after()

Prismic\SearchForm::after (   $documentId)

Set the after parameter: the id of the document to start the results from (excluding that document).

Parameters
string$documentId
Returns
Prismic::SearchForm a clone of the SearchForm object with the new after parameter added

§ count()

Prismic\SearchForm::count ( )

Get the result count for this form

This uses a copy of the SearchForm with a page size of 1 (the smallest allowed) since all we care about is one of the returned non-result fields.

Returns
int Total number of results
Exceptions
RuntimeException

§ fetch()

Prismic\SearchForm::fetch ( )

Set the fetch parameter: restrict the fields to retrieve for a document. You can pass in parameter an array of strings, or several strings.

Returns
Prismic::SearchForm a clone of the SearchForm object with the new fetch parameter added

§ fetchLinks()

Prismic\SearchForm::fetchLinks ( )

Set the fetchLinks parameter: additional fields to retrieve for DocumentLink, You can pass in parameter an array of strings, or several strings.

Returns
Prismic::SearchForm a clone of the SearchForm object with the new fetchLinks parameter added

§ getData()

Prismic\SearchForm::getData ( )

Get the parameters we're about to submit.

Returns
array

§ isCached()

Prismic\SearchForm::isCached ( )

Checks if the results for this form are already cached

Returns
boolean true if the results for this form are fresh in the cache, false otherwise

§ orderings()

Prismic\SearchForm::orderings ( )

Set the query's ordering, setting in what order the documents must be retrieved.

Returns
Prismic::SearchForm a clone of the SearchForm object with the new orderings parameter added

§ page()

Prismic\SearchForm::page (   $page)

Set the query's page, for the pagination.

Parameters
int$page
Returns
Prismic::SearchForm a clone of the SearchForm object with the new page parameter added

§ pageSize()

Prismic\SearchForm::pageSize (   $pageSize)

Set the query's page size, for the pagination.

Parameters
int$pageSize
Returns
Prismic::SearchForm a clone of the SearchForm object with the new pageSize parameter added

§ query()

Prismic\SearchForm::query ( )

Set the query's predicates themselves. You can pass a String representing a query as parameter, or one or multiple Predicates to build an "AND" query

Returns
Prismic::SearchForm a clone of the SearchForm object with the new predicate or predicates added

§ ref()

Prismic\SearchForm::ref (   $ref)

Set the repository's ref.

Parameters
string | \Prismic\Ref$refthe ref we wish to query on, or its ID.
Returns
Prismic::SearchForm a clone of the SearchForm object with the new ref parameter added

§ submit()

Prismic\SearchForm::submit ( )

Submit the current API call, and unmarshalls the result into PHP objects.

Returns
Prismic::Response the result of the call
Exceptions
RuntimeException

§ url()

Prismic\SearchForm::url ( )

Get the URL for this form

Returns
string the URL

The documentation for this class was generated from the following file: