Use SoapClient in cakephp

Hello everyone, how to use this php code in cakephp 3 by passing the variables?


 ini_set("soap.wsdl_cache_enabled", 0); 
 $client = new SoapClient($url,array('cache_wsdl' => WSDL_CACHE_NONE)); 
 $array=array( 'merchantId'=>'PP-F105', 
 'description'=>'achat en ligne', 




   catch(Exception $e)
  echo $e->getMessage();

Hi Yves,

It should work. I have implemented the SoapClient recently in a project. Have you tried to execute this code?

The main difference or thing I would suggest is to add the right import:

use SoapClient;


When I run this single code in a php file it works fine, but in a controller under cakephp I get no response.

should I create a controller action template file containing the code?
Should I enter the code in a controller or single action in a template file? I am new to cakephp and I use version 3.8
Thank you for helping me.

That would depend on your project. In my case, since I invoke this kind of code from scheduled shells, I make the calls inside my model.

But I should clarify that you should never put this kind of code in a template file. This is not code suitable for a view.


can you give me some guidelines to adapt the code of the file to my project in cakephp. In fact, this project consists of subscribing to offers and then making payments via the code in the file.
I beg you to guide me. thank you

As far as I know, you could begin by:

  1. Defining where to put the code. Wich model or controller should be responsible for this behavior
  2. Then, add the dependency to that class:

use SoapClient;

  1. Create a method that does the job
  2. Put your code in that method


Thank you. I followed all of your instructions and it works but I see that there is no redirect to the payout site. And I see that it is at the level of

the redirection is not done. How can I adapt this redirect code to cakephp?
Thank you for you precious help

You’re asking how to redirect to a different URL in Cake3?

thank you I will come back to you