Hey guys/gals,
I’m beginning the process of breaking our PHP app that is built inside CraftCMS out into a Yii2 app. Before I get into my question(s) here are some background details:
Tech stack:
CraftCMS 2.6.2993 (uses Yii 1.1.19)
AngularJS (1.6)
PHP 7.0.x
Ubuntu 16.04 (Apache 2.4.18)
How it works:
1.) User visits a URL and Craft determines that’s a URL we have defined (non 404).
2.) CraftCMS serves up the HTML via a template which we plug our angular app/partials into.
3.) User interacts with something on the screen (ie: submit button) that requires us to go get data from an external source (another REST api).
4.) JS function called which runs an $http.post() to the backend (same server so just posting to index.php).
5.) CraftCMS controller receives request and processes then returns JSON back to the AngularJS app.
What I need to do:
Run Yii along side CraftCMS on the same server and have them differentiate which one should be receiving given request.
Move template loading into YII (that’s phase 2).
The end goal is to have CraftCMS run as “headless/content as a service” where it’s essentially just a content management API to request content from and serve up on the page. Yii will then be handling all of the template loading and PHP business logic instead of having them as CraftCMS plugins.
Technical details:
Currently the way we call CraftCMS to get session data/etc is to do an $http.post() to /index.php and the postbody contains an "action" key that specifies which counter should receive this request.
Unfortunately I’m having trouble calling a Yii controller using the same logic. We have a “validate” plugin that contains a controller “Validate_AddressController.php” with a function “actionValidateAddress()”. This action receives a JSON body with the address and it then calls out to an external vendor to actually validate the address.
However, when I try to post to this controller action I’m unable to hit it. It appears that CraftCMS is receiving the request first and then returning a 404 immediately and/or YII is never receiving the request.
Folder Structure:
<project folder>
<craft>
<backend>
<yii files>
<controllers>
- AddressController.php (the file I want to call).
<src>
<js files>
How can I set this up to differentiate which requests should go to CraftCMS and which ones should go to Yii2? Am I attempting to post incorrectly to Yii? I’ve tried to do $http.post(’/address/validateAddress’, {body}) but this doesn’t seem to work.
TL;DR – I want to treat Yii2 almost like a restful API but it needs to exist on the same server as another YII app.