phalcon/cphalcon · error · Phalcon\Assets\Exceptions\CollectionNotFound
The collection '{name}' does not exist in the manager
Error message
The collection '{name}' does not exist in the manager What it means
Phalcon\Assets\Manager::get(name) returns a named collection previously created in the manager. Collections live in an in-memory map per Manager instance; if the name is not a key in that map the manager throws CollectionNotFound instead of returning null.
Source
Thrown at phalcon/Assets/Manager.zep:299
return this->has(name);
}
/**
* Returns a collection by its id.
*
* ```php
* $scripts = $assets->get("js");
* ```
*
* @param string $name
*
* @return Collection
* @throws Exception
*/
public function get( string name) -> <Collection>
{
if unlikely true !== isset(this->collections[name]) {
throw new CollectionNotFound(name);
}
return this->collections[name];
}
/**
* Returns existing collections in the manager
*
* @return Collection[]
*/
public function getCollections() -> <Collection[]>
{
return this->collections;
}
/**
* Returns the CSS collection of assets
*View on GitHub (pinned to b7419de9cd)
Solutions
- Create the collection before retrieving it: `$assets->collection('js')->addJs('js/app.js')` or `$assets->create(...)`
- Guard with the built-in check: `if ($assets->has('js')) { ... }`
- List what actually exists: `print_r(array_keys($assets->getCollections()))`
- Make sure the 'assets' DI service is shared so all code sees the same Manager instance
Example fix
// before
$collection = $assets->get('footerJs'); // CollectionNotFound
// after
$assets->collection('footerJs')->addJs('js/footer.js', true, false);
$collection = $assets->get('footerJs'); Defensive patterns
Strategy: validation
Validate before calling
if ($assets->has('js')) {
$collection = $assets->get('js');
} else {
$collection = $assets->collection('js'); // create on first use
} Try / catch
try {
$collection = $assets->get('footerJs');
} catch (\Phalcon\Assets\Exceptions\CollectionNotFound $e) {
$collection = $assets->collection('footerJs'); // lazy-create then populate
} Prevention
- Use Manager::has(name) before get(name) for optional collections
- Define collection names as constants shared between providers and templates
- Register the 'assets' DI service as shared so collection state survives injections
When it happens
Trigger: `$assets->get('js')` before any `$assets->create('js', ...)` / `$assets->collection('js')->add(...)`; a typo or case mismatch in the name; calling get() on a fresh Manager instance (DI service configured as shared=false or re-instantiated) after the collection was registered on a different instance.
Common situations: Collections registered in a bootstrap/provider that did not run for the current module; DI definition accidentally non-shared so each injection gets an empty Manager; name drift between template ('footerJs') and provider ('footer-js').
Related errors
- Collection does not have an annotation called '{name}'
- Module '{name}' is not registered in the application
- Asset's content for '{path}' cannot be read
- Path '{path}' is not a valid target path
- Path '{path}' is not a valid target path, it is a directory.
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/36297360098a5562.
Report an issue: GitHub.