douzhi8244 2016-04-09 16:34
浏览 69

简单轻量级的PHP控制器

I'm currently developing on a professional basis in PHP, noteably cakephp. I haven't spend much time in in the realm of procedural php, hence why I'm here

I have a college project with an Arduino board, where I need to interact via web browser with the on board API, and have a simple button interface driving it. I intend to install a simple project on the webserver and make two calls to the api.

My scenario is this: Post form form either button, Controller evaluates the button press, creates a GET request for the API, and redirects to a certain page. I can easily do this in cake, but I don't see the need to install a chunky framework for such a tiny, single page single controller application.

Is there a lightweight solution available to accommodate this, or would I be better off with just a single php page making the requests via ajax and updating the page content with jquery or something like that

  • 写回答

1条回答 默认 最新

  • doushi1510 2016-04-12 09:10
    关注

    If you want to use a framework (maybe you see this increasing in size over the next few years) then look at something like Silex

    It is pretty simple to pick up and basically allows simple routing and allows for a simple REST API to be setup.

    Otherwise you can just handle this with a single PHP files:

    <script>
       $(document).ready(function() {
           //jquery here if you want to do it async
    
           $(form).submit(function(e) {
    
                $.post('/location/of/script.php, serialize(form), function(data) {
                     //do stuff with data
                }
           }
       });
    </script>
    
    <!-- HTML CODE GOES HERE -->
    

    HTML code for form & button:

    <form method="POST">
        <input type="submit" value="Submit">
    </form>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改