DbPanel
API reference › Debug › panels › DbPanel
Renders the database queries captured by the Database collector.
Presents the queries grid with per-query timings, the duplicate-query summary, and the EXPLAIN action that powers the
grid’s inline plan toggle; data acquisition lives in DbCollector.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$actions | array<string, | Standalone actions merged into the debug module’s Module::$actionMap, keyed by action ID. Default: []. | yii\ |
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$criticalQueryThreshold | int| | Critical-query-count threshold; when the captured query count exceeds this value the toolbar item flips to a warning state. null disables the check. Default: null. | DbPanel |
$db | string | Application component id of the DB connection used to run EXPLAIN queries. Default: 'db'. | DbPanel |
$defaultFilter | array<string, | Default filter applied to the queries grid as property => value (for example, ['type' => 'SELECT']). Default: []. | DbPanel |
$defaultOrder | array<string, | Default sort order applied to the queries grid as property => SORT_* (for example, ['duration' => SORT_DESC]). Default: ['seq' => SORT_ASC]. | DbPanel |
$detail read-only | string | Rendered detail view. | DbPanel |
$id | string | Panel unique identifier, assigned by the container module on registration. Default: ''. | yii\ |
$module | yii\| | Debug module owning this panel. Default: null. | yii\ |
$name read-only | string | Panel display name. | DbPanel |
$renderContext | PHPForge\ | Prepared render context, or null outside a debugger request. | yii\ |
$rows read-only | list<PHPForge\ | Rows in capture order. | DbPanel |
$summary read-only | PHPForge\ | Query metrics for the whole request. | DbPanel |
$tag | string | Tag of the request whose data this panel currently exposes. Default: ''. | yii\ |
$toolbarData read-only | array<string, | Toolbar envelope; [] to skip the panel. | yii\ |
$toolbarIcon read-only | string | Toolbar icon key. | DbPanel |
$types read-only | array<string, | type => type map suitable for a dropdown filter. | DbPanel |
$url read-only | string | Absolute URL to the panel detail view. | yii\ |
$viewPath read-only | string | Directory the panel views resolve against. | yii\ |
$error protected | PHPForge\ | Exception captured when the panel failed to produce or hydrate its snapshot. Default: null. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | This method is called after the object is created by cloning an existing one. | yii\ |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__unset() | Sets a component property to be null. | yii\ |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
capture() | Captures the panel payload for the current request. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
getDb() | Returns the DB connection used by the panel for EXPLAIN queries. | DbPanel |
getDetail() | Renders the detail view with the queries grid, the EXPLAIN toggle, and the duplicate-query summary. | DbPanel |
getError() | Returns the exception captured while collecting the panel payload, if any. | yii\ |
getName() | Returns the panel display name from the shared title enum. | DbPanel |
getRenderContext() | Returns the framework-neutral render context for the active debugger request, when one has been prepared. | yii\ |
getRows() | Returns the executed statements as typed rows hydrated from the stored snapshot. | DbPanel |
getSummary() | Returns the request-wide query metrics, computed once per hydrated snapshot and reused by every consumer. | DbPanel |
getToolbarData() | Returns the toolbar envelope wrapping the panel’s icon, items, and URL. | yii\ |
getToolbarIcon() | Returns the icon key from the shared panel icon enum. | DbPanel |
getTraceLine() | Builds a trace line for the toolbar through the shared Trace renderer, applying Module::$tracePathMappings and the configured Module::$traceLine template (or callable). | yii\ |
getTypes() | Returns the distinct SQL statement types captured for the request, keyed and valued by the same uppercase token. | DbPanel |
getUrl() | Returns the URL pointing to this panel’s detail view for the current request tag. | yii\ |
getViewPath() | Returns the directory under which the panel’s relative views resolve. | yii\ |
hasContent() | Returns whether the panel captured content for the loaded request. | yii\ |
hasError() | Returns true when setError() captured an exception during panel capture or hydration. | yii\ |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
hydrate() | Decodes the captured payload into the typed query snapshot and discards the memoized summary. | DbPanel |
init() | Registers the db-explain action. | DbPanel |
isEnabled() | Returns whether the panel can run: requires both a resolvable DB connection and the parent enable check. | DbPanel |
isQueryCountCritical() | Returns whether the given query count exceeds $criticalQueryThreshold. | DbPanel |
isVisible() | Returns whether the panel should appear in the toolbar and sidebar navigation. | yii\ |
moduleBound() | Completes module-dependent wiring after the container module binds $id and $module. | yii\ |
off() | Detaches an existing event handler from this component. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
setError() | Records an exception thrown during capture or hydration so LogTarget can surface it in the UI. | yii\ |
setRenderContext() | Installs the framework-neutral render context prepared for this panel by the debugger action. | yii\ |
trigger() | Triggers an event. | yii\ |
getModels() protected | Returns the typed query rows consumed by the queries grid. | DbPanel |
getToolbarItems() protected | Builds the query-count toolbar chip, with a warning when the count is critical or callers are excessive. | DbPanel |
getTotalQueryTime() protected | Returns the sum of every captured query’s duration. | DbPanel |
hasExplain() protected | Returns whether the DB connection’s driver supports the EXPLAIN action (currently mysql, sqlite, pgsql). | DbPanel |
Method details
Section titled “Method details”getDb()
Section titled “getDb() ”public function getDb(): yii\db\ConnectionReturns the DB connection used by the panel for EXPLAIN queries.
Returns
yii\db\Connection: Connection the EXPLAIN action runs against.
Throws
yii\base\InvalidConfigException: when the configured component id does not resolve to aConnection.
getDetail()
Section titled “getDetail() ”public function getDetail(): stringRenders the detail view with the queries grid, the EXPLAIN toggle, and the duplicate-query summary.
Returns
string: Rendered detail view.
Throws
yii\base\InvalidConfigException: when the DB connection cannot be resolved.
getName()
Section titled “getName() ”public function getName(): stringReturns the panel display name from the shared title enum.
Returns
string: Panel display name.
getRows()
Section titled “getRows() ”public function getRows(): list<PHPForge\Debug\Panel\Db\QueryRow>Returns the executed statements as typed rows hydrated from the stored snapshot.
Returns
list<PHPForge\Debug\Panel\Db\QueryRow>: Rows in capture order.
getSummary()
Section titled “getSummary() ”public function getSummary(): PHPForge\Debug\Panel\Db\DbSummaryReturns the request-wide query metrics, computed once per hydrated snapshot and reused by every consumer.
Returns
PHPForge\Debug\Panel\Db\DbSummary: Query metrics for the whole request.
getToolbarIcon()
Section titled “getToolbarIcon() ”public function getToolbarIcon(): stringReturns the icon key from the shared panel icon enum.
Returns
string: Toolbar icon key.
getTypes()
Section titled “getTypes() ”public function getTypes(): array<string, string>Returns the distinct SQL statement types captured for the request, keyed and valued by the same uppercase token.
Returns
array<string, string>: type => type map suitable for a dropdown filter.
hydrate()
Section titled “hydrate() ”public function hydrate(array<string, mixed> $payload): voidDecodes the captured payload into the typed query snapshot and discards the memoized summary.
Parameters
| Parameter | Type | Description |
|---|---|---|
$payload | array<string, | Captured panel payload. |
Throws
PHPForge\Debug\Storage\HydrationException: when the payload does not match the snapshot schema.
isEnabled()
Section titled “isEnabled() ”public function isEnabled(): boolReturns whether the panel can run: requires both a resolvable DB connection and the parent enable check.
Returns
bool: true when a DB connection resolves and the parent check passes; false otherwise.
isQueryCountCritical()
Section titled “isQueryCountCritical() ”public function isQueryCountCritical(int $count): boolReturns whether the given query count exceeds $criticalQueryThreshold.
Parameters
| Parameter | Type | Description |
|---|---|---|
$count | int | Query count to test. |
Returns
bool: true when the count exceeds the threshold; false otherwise.
getModels()
Section titled “getModels() ”protected function getModels(): list<PHPForge\Debug\Panel\Db\QueryRow>Returns the typed query rows consumed by the queries grid.
Returns
list<PHPForge\Debug\Panel\Db\QueryRow>: Rows in capture order, suitable for ArrayDataProvider.
getToolbarItems()
Section titled “getToolbarItems() ”protected function getToolbarItems(): array<int, array<string, mixed>>Builds the query-count toolbar chip, with a warning when the count is critical or callers are excessive.
Returns
array<int, array<string, mixed>>: Toolbar items, or [] when no queries were captured.
getTotalQueryTime()
Section titled “getTotalQueryTime() ”protected function getTotalQueryTime(): floatReturns the sum of every captured query’s duration.
Returns
float: Total query time, in milliseconds.
hasExplain()
Section titled “hasExplain() ”protected function hasExplain(): boolReturns whether the DB connection’s driver supports the EXPLAIN action (currently mysql, sqlite, pgsql).
Returns
bool: true when the driver supports EXPLAIN; false otherwise.
Throws
yii\base\InvalidConfigException: when the DB connection cannot be resolved.