Prefix AppController to call parent AppController

So I have this issue with prefixes.

I have Function Initialize() in prefix folder of as in Administrator prefix, but I want it to use the same appcontroller in main folder. parent::initialize(); does not work?

main AppController:
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
class AppController extends Controller
{
public function initialize()
{
echo “one”;
parent::initialize();

Adminisrator AppController(as prefix):
namespace App\Controller\Administrator;
use Cake\Controller\Controller;
use Cake\Event\Event;
class AppController extends Controller
{
public function initialize()
{
echo “two”;
parent::initialize();

localhost/
shows “one”

localhost/administrator
shows “two” only, I want it to show “onetwo” or “twoone”

Your prefixed AppController should extend the default AppController, not controller

namespace App\Controller\Administrator;
use App\Controller\AppController as BaseAppController;
use Cake\Event\Event;

class AppController extends BaseAppController
{
    public function initialize()
    {
        echo "two";
        parent::initialize();
        // prints "twoone"
    }
}
1 Like

worked like a charm. This I did not know was possible. and it’s so simple. A lot of my work is dependent on this feature working. And that fixed it.

Thanks a lot.
J

"Computers are useless, they only give you answers"
Pablo Picasso