donglian1982 2014-03-12 03:47
浏览 30
已采纳

如何在CakePHP中访问不遵循命名约定的POST数据?

I'm experimenting with CakePHP and I'm just surprised by how hard is it to accomplish the very simple task of reading a POST parameter.

The problem is, I don't use a form to submit the data. I'm using CakePHP as an API for my application and the provided values do not follow the naming conventions, so when I do pr($this->request->data) it just returns empty.

Suppose that I have parameters such as username and password sent to my /authenticate/login action and I need to read them to be able to perform the login. I don't want to require the users to provide parameters with names like data[Users][username].

I can't understand why CakePHP developers like to require you to do so to be able to access them in the application! Why making our lives harder and not just provide a simple function like $this->input->post('username')?

  • 写回答

1条回答 默认 最新

  • duankun9280 2014-03-12 04:03
    关注

    There's nothing to stop you accessing the $_POST superglobal, your data will be in there.

    However, I don't recommend you go down this path. There's a reason that everyone recommends Convention over Configuration. For example, if you want to enable the security component so that people can't tamper with your forms, then you'll have to go back to the way that CakePHP recommends.

    I strongly recommend doing things the 'Cake way' for the moment, everything is a lot easier if you do things the way that CakePHP recommends, especially when you start creating sites are not just simple one-user test cases.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上