0

On the same server I have a Restler 3.0 API server and also a CakePHP 2.3 application, I want to be able to use CakePHP controller functions from the Restler app. Of course I don't want CakePHP to do any rendering, just to deal with the data.

I considered just doing a https request to the CakePHP app from the Restler api, but this seemed pretty inefficient for the client of the Restler server. I also considered using RabbitMQ to do RPC between the apps but RPC in PHP seemed like too much complexity for something i'm trying to keep simple.

Ideally in Restler i might have something like this:

<?php
class Content {
    function post() {
        // CakePHP stuff:
        $data = array('title'=>'fake data');
        $this->Content->create();
        if ($this->Content->save($data)) {
            return 'ok';
        }
    }
}

I'm completely open to any good ideas on the best way to achieve this integration.

user698883
  • 55
  • 1
  • 4
  • Cake is not designed to be used as a lib. It is a full stack framework. Normally you use other libs within cake, not the other way round. – dogmatic69 Jan 03 '13 at 12:40
  • this makes sense, so what would be the best way to integrate two frameworks - is a message queue the right way to do it? – user698883 Jan 04 '13 at 12:16

1 Answers1

0

Whether this is possible really depends on the nature of your environment.

Considerations:

  1. Does your controller use other cake framework components(Controllers, Models, components, etc.)? You might be hosed if this is the case because cake is convention oriented. Without the cake plumbing to interpret those conventions they are meaningless.

If you just need to repurpose some non-cake specific PHP logic you could always refactor it into its own php class or even just a .php file with some functions in it and share them between your Restler App and your Cake Application.

nsfyn55
  • 14,875
  • 8
  • 50
  • 77
  • yes it's quite a complex application so unfortunately uses almost all cake components. I tried to use Cake with a custom app\webroot\index.php file removing the dispatcher, and just calling the controller method directly - while this worked from a test.php file, trying to do it from within the Restler class i ran into loads of scope problems. – user698883 Jan 04 '13 at 12:10
  • Thats the problem. Having a centralized dispatcher is what allows cake to decorate the execution context and giving meaning to things like the `$uses` convention. Its not as simple as just repurposing the controller's behavior. Have you considered exposing the Cake app's behavior as a Restful URI itself? Consumers would be oblivious as to which server their requests were being directed. This might be a good stop gap. – nsfyn55 Jan 04 '13 at 14:45