snelg / cakephp-cors

CORS plugin for CakePHP 3
19 stars 2 forks source link

cakephp3 Cannot locate dispatcher filter named Cors.Cors #10

Open jkimilu opened 8 years ago

jkimilu commented 8 years ago

I am a newbie in cakephp and so far am loving it. Am trying to build a mobile app that will consume json apis within my cake, but i have not been successful as my cross domain requests are being blocked and thats how i have ended up here.

I have the pasted the following in bootstrap.php DispatcherFactory::add('Cors.Cors', ['routes' => [ 'mobilePosController' ]]);

also pasted the cors filter plugin into Plugins folder and renamed the folder from cakephp-cors to just Cors.

Why am getting the error in subject line above.

jkimilu commented 8 years ago

figured that i needed to load the plugin and then paste the dispatch code right after. No errors but still getting XMLHttpRequest cannot load http://192.168.0.12/rms/mobile-pos/login.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. Kindly assist how to get ride of this cross domain issue.

LeWestopher commented 8 years ago

Cake Controller classes follow the UpperCamelCase convention and typically you can omit the 'Controller' from controller class names when they're being called in a CakePHP controller specific context.

  1. Rename your controller to MobilePosController where it's defined.
  2. Redefine your route structure for the Cors dispatch factor config by adjusting for the UpperCamelCase convention and omitting the "Controller" prefix on the class name:
DispatcherFactory::add('Cors.Cors', ['routes' => [
    'MobilePos'
]]);

If this doesn't work for you, I would suggest running the tests and seeing if any tests are failing on your specific version of Cake.