Function to forward controller action to another controller #199

Closed
opened 2020-08-04 23:55:34 +00:00 by jamie · 4 comments
jamie commented 2020-08-04 23:55:34 +00:00 (Migrated from git.hazaar.io)

I have a situation where, due to a poorly implemented MVC application, there is a lot of code in a controller action that needs to be used by another controller action. Due to the size of the code and the method by which it was implemented, it would require the entire action to be re-written using correct MVC techniques in order to create common code in a Model that can be used from the new action that requires similar functionality.

To get around this issue in a more simple way, I have come up with a plan to make it simple to call another controller (and action) from the requested action. This will setup the controller, including initialising it, call the action and transfer all view and view data back to the original controller which can then make any required modifications before returning a response.

This would be executed possibly such as:

<?php
class TargetController {

  function action(){

    $this->forwardAction('index', 'action');

    $this->view->parameter = 'another value';

  }

}
?>

This would forward a request to /target/action internally to /index/action and then the target updates a view data parameter called parameter with a different value.

I have a situation where, due to a poorly implemented MVC application, there is a lot of code in a controller action that needs to be used by another controller action. Due to the size of the code and the method by which it was implemented, it would require the entire action to be re-written using correct MVC techniques in order to create common code in a Model that can be used from the new action that requires similar functionality. To get around this issue in a more simple way, I have come up with a plan to make it simple to call another controller (and action) from the requested action. This will setup the controller, including initialising it, call the action and transfer all view and view data back to the original controller which can then make any required modifications before returning a response. This would be executed possibly such as: ```php <?php class TargetController { function action(){ $this->forwardAction('index', 'action'); $this->view->parameter = 'another value'; } } ?> ``` This would forward a request to ```/target/action``` internally to ```/index/action``` and then the target updates a view data parameter called ```parameter``` with a different value.
jamie commented 2020-08-05 00:02:13 +00:00 (Migrated from git.hazaar.io)

mentioned in merge request !93

mentioned in merge request !93
jamie commented 2020-08-05 00:02:13 +00:00 (Migrated from git.hazaar.io)

created merge request !93 to address this issue

created merge request !93 to address this issue
jamie commented 2020-08-05 03:16:55 +00:00 (Migrated from git.hazaar.io)

closed via merge request !93

closed via merge request !93
jamie commented 2020-08-05 03:16:55 +00:00 (Migrated from git.hazaar.io)

mentioned in commit 9f9fb3bf9204b304b7e82af8a066e7d7958e2e73

mentioned in commit 9f9fb3bf9204b304b7e82af8a066e7d7958e2e73
jamie self-assigned this 2025-09-04 01:15:31 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/framework#199
No description provided.