# ViewFinderTrait

> ViewFinderTrait implements the method getViewNames for finding views in a database.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › ViewFinderTrait

| trait | `yii\db\ViewFinderTrait` |
| --- | --- |
| Since | 2.0.12 |
| Source | [`framework/db/ViewFinderTrait.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/ViewFinderTrait.php#L18) |

Used by 2 types:

- [`yii\db\mssql\Schema`](/docs/api/yii/db/mssql/schema/index.md)
- [`yii\db\pgsql\Schema`](/docs/api/yii/db/pgsql/schema/index.md)

ViewFinderTrait implements the method getViewNames for finding views in a database.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`getViewNames()`](#method-getViewNames) | Returns all view names in the database. | `ViewFinderTrait` |
| [`findViewNames()`](#method-findViewNames) protected abstract | Returns all views names in the database. | `ViewFinderTrait` |

## Method details

### getViewNames() <span id="method-getViewNames"></span>

```php
public function getViewNames(string $schema = '', bool $refresh = false): string[]
```

Returns all view names in the database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the views. Defaults to empty string, meaning the current or default schema name. If not empty, the returned view names will be prefixed with the schema name. |
| `$refresh` | `bool` | Whether to fetch the latest available view names. If this is false, view names fetched previously (if available) will be returned. |

**Returns**

`string[]`: All view names in the database.

### findViewNames() <span id="method-findViewNames"></span>

```php
abstract protected function findViewNames(string $schema = ''): array
```

Returns all views names in the database.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$schema` | `string` | The schema of the views. Defaults to empty string, meaning the current or default schema. |

**Returns**

`array`: All views names in the database. The names have NO schema name prefix.