Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8969651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:37:22+00:00 2026-06-15T17:37:22+00:00

I have an Action method in Foo Controller which requires parameters: public function fooAction($one,

  • 0

I have an Action method in Foo Controller which requires parameters:

public function fooAction($one, $two) {
    $a = one;
    $b = $two;
}

And I need to forward to that method from the other method of some Boo Controller. And one of those parameters has to be by reference parameter. The only example that the manual has is this:

$result = $this->forward()->dispatch('Boo\Controller\Boo', array('action' => 'boo'));

No any additional parameters. But they write:

$params is an optional array of parameters with which to see a
RouteMatch object for purposes of this specific request.

So, I tried:

$result = $this->forward()->dispatch('Boo\Controller\Boo', array(
                                                      'action' => 'boo',
                                                      'one' => &$one,
                                                      'two' => $two,
                                                 ));

But it doesn’t work.

Is there any way to pass additional parameters to forward controller?

UPD:

These do not work too:

$result = $this->forward()->dispatch('Boo\Controller\Boo', array(
                                                      'action' => 'boo',
                                                      'params' => array(
                                                          'one' => &$one,
                                                          'two' => $two,
                                                     )));


$result = $this->forward()->dispatch('Boo\Controller\Boo', array(
                                                      'action' => 'boo',
                                                      'options' => array(
                                                          'one' => &$one,
                                                          'two' => $two,
                                                     )));

UPD 2:

I still can’t get the functionality I want (to pass parameters with the forward plugin) but I found other solutions. Before calling the forward plugin I set the variables to the Request object and after the forward I get them from the Request in my boo Action of my Boo\Controller\BooController:

// in Foo::fooAction
$this->getRequest()->one = &$one;
$this->getRequest()->two = $two;
$result = $this->forward()->dispatch('Boo\Controller\Boo', array('action' => 'boo'));

// in Boo::booAction
$a = $this->getRequest()->one;
$b = $this->getRequest()->two;

Stupid solution, it will not work with Ajax requests. Still interested how to pass parameters with the forward plugin. OR MAYBE how to get them in the booAction. Because there in no anything in the Request if I pass them with the forward.

UPD 3 and Final:

I finally found where they’ve decided to hide parameters I pass with the forward plugin. They put them in the RouteMatch object.

– Tryyyy to guess where we’ve hidden your params… Oh yeeah, they are in the RouteMatch, of course they are there, didn’t you think smth else?

And NO ANY info in the forward plugin section of the manual!

To get params, I have to do this in my BooController::booAction:

$param = $this->getEvent()->getRouteMatch()->getParam('nameOfParam');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:37:23+00:00Added an answer on June 15, 2026 at 5:37 pm

    You can create a container class and use it in both controllers

    in module.conf

    public function getServiceConfig()
    {
        return array(
            'invokables' => array(
                'my_handy_container'        => 'path\container_class_name',
            )
        );
    }
    

    Create a getter in both controllers:

    public function getMyHandyContainer()
    {
        if (!$this->myHandyContainer) {
            $this->myHandyContainer = $this->getServiceLocator()->get('my_handy_container');
        }
        return $this->myHandyContainer;
    }
    

    And call it using:

    $myContainer = $this->getMyHandyContainer()->myHandyContainer;
    $myContainer->foo = 5; // set something
    

    ZF2 way to pass vars using forward

    In the passing method do:

    return $this->forward()->dispatch('controller_name', [
        'action' => 'whatever',
        'varname' => $value,
        'varname2' => $value2
    ]);
    

    In the invoked controller method, do:

    $param2 = $this->params()->fromRoute('varname2',false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two methods with the following signatures void Invoke(Action method) void Foo() What
I have a controller action that calls a model method which generates a serialized
Suppose, I have a controller named category with an action method, Index which takes
I have a spring (3.1) controller action method like this: @RequestMapping(value=/{id}) public String myAction(@PathVariable(id)
I have an action method without parameters. The QueryString collection contain all of my
I have an action method that takes in two different objects. I am posting
I have the following code in my controller action method: if (User.Identity.IsAuthenticated) { //
I have problem with ObjectContext.SaveChanges method: public void Save(Action<object, object> action) { EventAggregator.GetEvent<EntityServiceRequestingEvent>().Publish(true); var
I have a Rails controller action to test. In that action, a method User.can?
On ASP.NET MVC 3, assume that we have following controller action: public ActionResult Index()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.