Jump to content

Adding an ajax api custom route


jsantari
 Share

Recommended Posts

Trying to do some ajax calls to an api  named somedomain.com/xapi/index.php using intercoolerjs in my home page. I'm trying to make calls like this in intercoolerjs. somedomain.com/xapi/controller/method. Looked through a bunch of the posts but nothing seems to match what I am trying to do. Is there a change I can make to the htaccess file  to get this to work? Anyone have a suggestion on this or is there a better way to handle the api?

Link to comment
Share on other sites

I looked at some of the posts on that module and it's not what I'm looking for. I can handle the intercoolerjs side fine. I've done a few small projects with it using mysql & slim as the route handler. I can use a simple template in PW like api.php and call url's like somedomain.com/api/?c=controller&m=method but then intercoolerjs can't take advantage of the dependency system. Basically what I'd like is to just be able to route to the subfolder with PW getting out of the way. I can bootstrap PW at that point and do what I want.

Link to comment
Share on other sites

Do you mean that the PW htaccess is disallowing access to your PHP file (you are getting the 404 page)?

PW blocks direct access to PHP files inside /site/ but you should be able to access it inside the root, e.g.

/api.php

...or...

/xapi/index.php

 

Link to comment
Share on other sites

@Robin SIt will go to api.php when that was setup as a template for the page /api. I did figure out that PHP files don't work in /site/ and I moved it to /xapi below root. I can access it now and just figured out how to get what I wanted.

@LostKobrakaiMoving it outside of /site/ as mentioned above got it working with parameters but still didn't get me the ability to use segments. Was able to get that working by adding a rewrite rule in the PW .htaccess. Don't see any other way to get it to work so that will need to go into any updated .htaccess I use down the road.

Link to comment
Share on other sites

  • 1 month later...
On 13.1.2017 at 7:23 PM, jsantari said:

 I'm trying to make calls like this in intercoolerjs. somedomain.com/xapi/controller/method.

Do you mean...  you want handle the request/url in your template (controller) and take the url segment (method) and map it to a corresponding method in a class of your template?

...like Codeigniter Framework has it? url/xxx/yyy/zzz calls method yyy in controller xxx with zzz as argument?  Or do you just don´t know how to use url segments?

 

here this guy uses this kind of url segments...

 

Link to comment
Share on other sites

 Share

×
×
  • Create New...