Dispatcher to Server in external applicaiton


#1

Hi
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.

Dave


#2

I’ve used something like this:

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

$request = ServerRequestFactory::fromGlobals();

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

Hope it helps.


#3

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

https://www.example.com/cakecontent.php

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)