requestAction shows a blank page in CakePHP 3.1

229 views Asked by At

I am using CakePHP 3.1 and whenever I make use of requestAction, the page goes blank while I get an error in the console. The basic code is:-

$test = $this->requestAction('/dockets/find'.$articleList->id, [], ['return']);

While the dummy controller method is:-

function find($docket_id)
{
      return 0;
}

Whenever I include the code in any view file (.ctp file), I get a blank page. I also get a console error saying the current url cannot be found. The url works fine if I don't include the above code.

1

There are 1 answers

2
drmonkeyninja On

Your first argument for requestAction is wrong, there is a missing / after find. It should be:-

$test = $this->requestAction('/dockets/find/' . $articleList->id, [], ['return']);

Alternatively, you could call requestAction using a router array:-

$test = $this->requestAction(
    [
        'controller' => 'dockets', 
        'action' => 'find', 
        $articleList->id
    ], 
    [], 
    ['return']
);