PHP Templating API: getModels() Print

  • 0

Description:

The getModels() function gets a list of models that are present in the system. Based on the arguments that are passed to it will determine which and how many models are returned.

Sample Usage:

$modelobj = $api->getModels();

$modelobj = $api->getModels(["id" => 1]);

$modelobj = $api->getModels([
"page" => 1,
"id" => 1,
"numperpage" => 20,
"gender" => "F",
"startwith" => "A",
"sort" => "date",
"sort_reverse" => "1",
"subsiteid" => 1,
"extrafield_filter" => [
"4" => "Search String",
"5" => "Search",
],

]);

echo "\nNumber of models returned: " . $modelobj->modelcount;
echo "\nNumber of models total: " . $modelobj->modeltotal;
echo "\nNumber of pages: " . $modelobj->numpages;
echo "\nModels:\n";
print_r($modelobj->models);

Returning Attributes:

This function call will return a StdObject object with the following attributes:

models:

This is a multi-dimensional array that returns any models that match search criteria.

modelcount:

The number of sets within the models attribute.

numpages:

A total number of pages that are available. For instance, if modeltotal = 400 and the system has a numperpage value of 20, this value will be 20.

modeltotal:

A total number of models that are available, regardless of pagination.

Arguments:

page:

This paginates the model list. This way, if you specify "page" => 2, it will show a different list of models than if you specify "page" => 1.

This is useful if the page you're calling this function on is paginated and you want to show different updates on page 2 of your page than page 1.

By default, the system sets this value to 1 if not specified when passing along to the system.

id:

This filters the results by model id. If set, this will only return a set of the specified model id, if it is available for release and is present on the current site.

numperpage:

If specified, determines the maximum number of results to show.

By default, the system looks at the value of "Models per page" under Plugins -> Models -> Configure.

gender:

If specified, only return models that belong to the specified gender.

By default, the system attempts to see if the existing site is set to limit results on the models page to a specified gender, if set. Generally, this is a setting that is specified within all-access site setups.

startwith:

If specified, only show models that begin with the specified letter.

By default, the system does not filter results by letter.

sort:

Specify sorting order of sets.

Valid values are: id,name, date, rating, gender, random.

By default, the system will sort by date.

Note: Doing a database sort by random creates a temporary table within mysql, and may result in reduced performance. Only choose this sorting option when absolutely necessary.

sort_reverse:

If this is set to 1, reverse the sorting order as specified within "sort"

subsiteid:

If specified, limit models belonging to a specified all-access subsite id. If this value is set to 0, show sets from all sites.

By default, the system will detect if the current area belongs to an all-access subsite, and use that value.

Note: If you specify a non-zero value for subsiteid, all-access must be available within this system. Otherwise, an Exception will be triggered.

extrafield_filter:

If specified, limit models based on extra field search criteria.

In order to do a search with this, you'll need to pass an associative array, where:

- The key specifies the Extra Field Id of the item you're searching. You can find this ID in /cms_admin/plugins/extrafields/extrafields.php

- The value of the array is an exact match of the string that you're searching.

Examples:

"extrafield_filter" => [
  "4" => "Female",
],

"extrafield_filter" => [
"4" => "Male",
"6" => "Scorpio",
],


Was this answer helpful?

« Back

This site uses cookies to personalize content and to analyze traffic. You consent to our cookies if you continue to use our website. Read our Privacy Policy to learn more. Please Agree or Exit