# Loading models in external scripts

**URL:** <https://forum.getkirby.com/t/loading-models-in-external-scripts/2668>\
**Category:** Questions\
**Tags:** v2\
**Created:** [November 29, 2015, 10:23pm UTC](https://forum.getkirby.com/t/loading-models-in-external-scripts/2668 "2015-11-29T22:23:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SQBiz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/sqbiz/32/5014_2.png) [@SQBiz](https://forum.getkirby.com/u/SQBiz)\
**Post date:** [November 29, 2015, 10:23pm UTC](https://forum.getkirby.com/t/loading-models-in-external-scripts/2668/1 "2015-11-29T22:23:26Z")

</div>

I have a script that handles a bunch of searching and filtering. It’s in `/assets/php/do_search.php`, so not part of kirby’s core. So, I start it up with:

```
define('DS', DIRECTORY_SEPARATOR);
require($_SERVER["DOCUMENT_ROOT"] . DS . 'kirby' . DS . 'bootstrap.php');
$kirby = kirby();
$site = $kirby->site();
$params = $_POST;
$site->load('models');

```

I’m able to use Kirby throughout, filtering through pages and returning succinct results. Instead of returning the entire page as a search result, I just return a few strings:

```
$filtered_result_arr['title'] = (string)$filtered_result->title();
$filtered_result_arr['author'] = (string)$filtered_result->parent()->title();
$filtered_result_arr['categories'] = (string)$filtered_result->get_categories();
$filtered_result_arr['url'] = "/" . (string)$filtered_result->uri();

```

This is all working, except for the `get_categories()` function - which is included in the template’s model. I’ve included `$site->load('models')` at the beginning of the script - but this seems to have no effect.

Is there anything I can do here to access the models?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [November 30, 2015, 10:24am UTC](https://forum.getkirby.com/t/loading-models-in-external-scripts/2668/2 "2015-11-30T10:24:50Z")

</div>

A more robust solution would be to use a route inside a Kirby plugin. You can even use the same URL for the route. 😃

I think the syntax for loading models should be `$kirby->models()` though.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:04pm UTC](https://forum.getkirby.com/t/loading-models-in-external-scripts/2668/3 "2025-02-06T17:04:05Z")

</div>


