Undefined property Cms\Components\ViewBag::assetUrlPath

Hi there,

I just updated my October website from v3.7 to v4.0 and followed the upgrade guide, but I get the following error when viewing the front-end website or settings pages in the backend (SettingsModel):

Call to undefined property Cms\Components\ViewBag::assetUrlPath
~/vendor/october/rain/src/Extension/ExtendableTrait.php line 457

I have tried removing PHP files from the storage/framework folder and cleared cache. I also wanted to run the ‘php artisan october:optimize’ command, but this too returns the same error.

I use a local environment with Laravel Herd and using php 8.3.

Does anybody have an idea how to fix this?

Thanks!

Hey @kevin-invato

The error at ExtendableTrait.php line 457 suggests the Extendable system is trying to access assetUrlPath as a dynamic property, but we need to know what is calling it. The stack trace would reveal if it’s:

  • Twig template code (e.g., {{ viewBag.assetUrlPath }})
  • A plugin accessing ViewBag properties
  • Internal CMS rendering logic
  • Something else entirely

I used Augment (AI) to analyse the stracktrace and this is the response. Weird thing about the settingsmodel pages is that when there is a pagefinder fieldtype, it breaks. If I remove the pagefinder field the page works, but I get a lot of richeditor errors in the console.

Analysis of the Stacktrace

The Problem

The error occurs when October CMS tries to initialize a ViewBag component:

Error location:

The Error Flow

  1. Trigger (#32-#19): A PageFinder formwidget in the backend tries to resolve a page (ketels/cv-ketel)
  2. Page Loading (#19-#6): October CMS loads the page and triggers the afterFetch() event
  3. ViewBag Initialization (#3-#2):
  • CmsCompoundObject->getViewBag() is called
  • This creates a new ViewBag component via ComponentBase->__construct()
  1. Property Assignment (#1):
  • In

ComponentBase.php

line 107, $this->assetUrlPath = $this->getComponentAssetUrlPath() is executed

  • This calls Extendable->__set('assetUrlPath', '/modules/cms')
  1. The Error (#0):
  • ExtendableTrait->extendableSet() fails because ViewBag has no assetUrlPath property and doesn’t define a __set() method

Why Does This Fail?

In

ViewBag.php

:

  • :white_check_mark: Has a __get() method that returns null for unknown properties
  • :x: Has no __set() method
  • :x: Has a __isset() method that returns false for unknown properties

The Problem: When ComponentBase->__construct() tries to set $this->assetUrlPath:

  1. PHP calls __set() because the property doesn’t exist
  2. ViewBag has no own __set(), so it goes to the parent (Extendable)
  3. Extendable->__set() calls extendableSet()
  4. extendableSet() checks if the property exists via property_exists() or __isset()
  5. ViewBag->__isset('assetUrlPath') returns false
  6. BOOM - Exception: “Call to undefined property”

Why Did This Work in v3.x?

In October CMS v3.x, the ExtendableTrait was probably less strict, or ViewBag had a different implementation that allowed this.

The Solution

There are 3 possible solutions:

Option 1: Fix in ViewBag (what I did earlier)

  • Add __set() method that delegates to parent::__set()
  • Modify __get() and __isset() to fall back to parent

Option 2: Fix in ComponentBase

  • Check if the component is a ViewBag and skip setting assetUrlPath
  • Not ideal, but would work

Option 3: Report as bug to October CMS

  • This is clearly a regression in v4.0
  • The ViewBag component should work like other components

Conclusion

This is a bug in October CMS v4.0. The ViewBag component has incomplete magic methods that are not compatible with how ComponentBase tries to set properties. The fix I implemented earlier (option 1) is the correct solution, but should actually be implemented by the October CMS team.

PS: the first item in the errorflow is referring to ketels/cv-ketel, but it’s different for all settingsmodel. Its the value of the pagefinder data.

1 Like

Hi @kevin-invato

Thanks for this report. Something here doesn’t add up, could you check your codebase to ensure that this property exists here: https://github.com/octobercms/october-private/blob/4.x/modules/system/traits/AssetMaker.php#L39

As we see, the property is defined and is public:

/**
 * @var string assetUrlPath specifies the public path to the asset directory.
 */
public $assetUrlPath;

This means the error doesn’t quite make sense in the current codebase, and this analysis doesn’t appear to identify the issue.