Roots Discourse

ACF Custom Modules with Custom Controller? Possible?

Hi Guys…

just wondering If I’m on the right path… :wink:

Well, I just read nearly all entries here related to ACF, controllers etc. but maybe I misunderstand something.

What I wanted to achieve is, having ACF Modules based on flexible layout feature, each layout with its own Module/ Controller. Nothing new. Done that years ago iterating over the values including different templates through wp template system (custom structure & no Sage)

With Sage, these modules could be on any page, so I startet with App.php.
But with Sage9 & Blade I wanted to stay in the given structure with controllers.

First, I’m only able to define controllers within the controllers folder app/Controllers. If I define one in a subfolder e. g. app/Controllers/Comps/ComponentOne.php I get an error, class not found, as class ComponentOne extends Controller (Sober\Controller\Controller) which searches only within folder app/Controller and not in e. g. /Comps, am I right?

=> possible to change that? Add some additional search folders?

I then came up with traits, defined a Component trait which uses single module traits through use. But I am currently struggling as based on traits everything is added to App class and I am not sure if all modules have unique vars & methods, to not be repetitive in code… And at the end all is located within App class.

I could do a component class, get all fields, load the corresponding partials and display vars but that would not be the controller way.

Anyone got this to work, iterate over the act layouts and use one separate controller for each layout which holds its own functionality and logic?

I appreciate any tips and tricks :wink:

Thanks in advance

Sober\Controller\Controller uses PSR-4 autoloading to pass data. The default namespace is App\Controllers. you can change that w/ the sober/controller/namespace filter.

add_filter('sober/controller/namespace', function () {
    return 'Data';


thx for your reply :wink:

If I understand it correctly, this filter changes the main namespace, e. g. return 'Data' outputs Data/App not found error, if I just test it without changing the namespace of App.php within /Controllers to namespace App\Data

What I wanted to achieve is some kind of subfolders within the /Controller folder to structure my controllers a bit more.

E. g. I have

/ Controllers
-- / Components
-- Components.php

namespace App\Controllers\Components;

use \Roots\WPConfig\Config;

use Sober\Controller\Controller;

class Components extends Controller {
    public function test (  ) {
        return 'test';

Throws an error, that no class was found Components within App\Controllers. So I inspected the sober controller file and think it’s just searching within the first level of Controller folder… It’s searching for classes which extends Controller class and then looks in Controller folder instead of the subfolder…

Maybe I got something wrong…

ThX in advance

BR Michael

No, that sounds right. Perhaps submit an issue at the soberwp repo for suggestions on hacking on the Sober\Controller\Loader.