weixin_33716154 2015-08-23 23:56 采纳率: 0%
浏览 33

如何“路由”到PHP方法?

I have a PHP class with a number of public methods. I'm not in a PHP framework environment, so I don't have the option to access methods via URL routes that's common in frameworks (e.g. domain.com/myclass/mymethod/). However, I do want to be able to call those methods directly via Ajax.

How can I do this? Can Ajax POST some parameters to the class to instantiate it and call the appropriate method and pass it the parameters the method needs?

  • 写回答

1条回答 默认 最新

  • Didn"t forge 2015-08-24 02:07
    关注

    You will have to define your routing in .htaccess to route all requests to a specific file which in turn will instantiate the necessary classes and calls the functions. Its just like what Phil and AbraCadaver said. You however will need a .htaccess to route your requests to that file.

    Also you will have to enable Apache mod_rewrite. URL rewriting is handled using apache's mod_rewrite.

    Hope this helps.

    评论

报告相同问题?