Dispatcher to Server in external applicaiton


I’ve previously embedded Cake content into other CMS systems using a mishmash of the default index.php and the following code

use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\DispatcherFactory;
App::uses(‘Dispatcher’, ‘Routing’);
$Dispatcher = new Dispatcher();
$url = “/client/index/”;
$Dispatcher->dispatch(new CakeRequest($url), new CakeResponse(array(‘charset’ => Configure::read(‘App.encoding’))));

which worked great pulling the Cake content in however I’m struggling to convert this over to Http\Server for 3.6/3.7

Is anyone able to assist ?

Thanks in advance.



I’ve used something like this:

$application = new Application(APP_ROOT . 'config');
$server = new Server($application);

$request = ServerRequestFactory::fromGlobals();

$response = $server->run($request);

Hope it helps.


Thanks, this is similar to what I had, which works ok if the URL is identical to the cake path - problem I have is this isn’t always the case.

Example - If I have a webpage in an external system


The cake content may be coming from

https://www.example.com/db/client/login (where /db/ is my usual cake dir, and client is the controller)

url = “/client/index/”;
new CakeRequest($url);

doesn’t seem to be interpreting correctly (and I see this is going to be removed in 4 as well)