Saturday, March 19, 2022

[FIXED] Setting global action on cakephp 3.3.5

Issue

I have a call to action button that opens a form for users to subscribe. I'm trying to have this form on the global header. The action subscribe() is in the App Controller but not sure how to call it from every single view.

I've tried a few things but haven't been able to make it work.

<?= $this->Form->create($subscription, ['controller' => 'App', 'action' => 'subscribe']) ?>

Any ideas? Thanks.


Solution

You could also use a named route.

/config/routes.php

    $routes->connect('/subscribe' , ['controller'=>'App', 'action'=>'subscribe'] , ['_name' => 'subscribe']);

in your view

<?= $this->Form->create('Subscripton', [url => ['_name' => 'subscribe']]); ?>


Answered By - Derek

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.