Search documentation of phoenix_kit

# PhoenixKitWeb.ContextController (phoenix_kit v1.7.87)

Copy Markdown View Source

Controller for handling dashboard context switching.

Provides POST endpoints that set the selected context ID(s) in the session and redirect back to the referring page.

## Routes

- `POST /context/:id` - Legacy single selector (backward compatible)
- `POST /context/:key/:id` - Multi-selector with keyed context

## Multi-Selector Behavior

When using multiple selectors, changing a parent selector will automatically reset dependent selectors based on their `on_parent_change` configuration:

- `:reset` (default) - Clears the dependent selector's stored ID
- `:keep` - Preserves the dependent selector's stored ID
- `{:redirect, path}` - Redirects to specified path instead of referer

## Summary

### Functions

set(conn, arg2)

Sets the current context for a specific selector key.

set_legacy(conn, map)

Sets context using the legacy single-selector session key.

## Functions

# set(conn, arg2)

Sets the current context for a specific selector key.

This is the multi-selector route that handles `POST /context/:key/:id`.

## Parameters

- `key` - The selector key (e.g., "organization", "project")
- `id` - The context ID to set as current

## Response

Redirects to the referer URL, or `/dashboard` if no referer is present. Dependent selectors may be reset based on their `on_parent_change` setting.

# set_legacy(conn, map)

Sets context using the legacy single-selector session key.