OctoberCMS - 如何在php部分的函数中访问组件的属性?

Is it possible to access the properties of a component e.g. blogPosts in the OnStart() function? If so, how?

title = "Blog Category"
url = "/blog/category/:slug/:page?"

[blogPosts]
categoryFilter = ":slug"
postsPerPage = 3
==
function onStart()
{
    // Access categoryFilter property
    $catfilter = ???
    ...
}
==

I got to ask why do you need to access the component properties?

You can access the parameter ':slug' $this->param('slug');.

This should work for you to get the array of properties.

function onStart() {
    $this['properties'] = collect($this->page->components['blogPosts'])->last()['postsPerPage'];
}

I am adding another way to get the properties from the array. I am assuming that properties is probably always last but if it isn't:

    $array = collect($this->page->components['blogPosts'])->toArray();
    $properties = [];
    foreach ( $array as $key => $property) {
        if ( strpos($key, 'properties') !== false ) {
            $properties[$key] = $property;
        }
    }
    $this['properties'] = $properties['postsPerPage'];