Automatic controller actions - CakePHP4

I have a bunch of pages that are really just html - they don’t have any content from models in them. Currently I have an action for each of them in the controller that just looks like

public function myaction() { }

public function myotheraction() { }

etc.

It feels like there must be a neater way of doing this so that any action that doesn’t need the controller to do anything just gets forwarded to the right view rather than having a series of actions that aren’t doing very much.

Have you seen the display() method in PagesController in the Cakephp 4.3 skeleton app? I think that does what you are looking for.

As noted in the documentation here, “[i]f you make the view file templates/Pages/about_us.php you can access it using the URL http://example.com/pages/about_us”.

If you don’t want ‘pages’ in the url, you could always add some custom routes which point to that display() method.

Thanks @Sort_Gez, that’s just the kind of thing I’m after. (I knew I’d seen something like this somewhere but couldn’t remember where.)

I’m now having trouble getting it working for some reason but I need to fiddle with it for a while to find out why.

1 Like