手动打包 CakePHP 的 save() 数据
我正在尝试为 cakephp 中的 save() 函数打包一些数据。我是 PHP 新手,所以我对如何在代码中实际编写以下内容感到困惑:
Array
(
[ModelName] => Array
(
[fieldname1] => 'value'
[fieldname2] => 'value'
)
)
谢谢!
I'm trying to package up some data for the save() function in cakephp. I'm new to PHP, so I'm confused about how to actually write the below in code:
Array
(
[ModelName] => Array
(
[fieldname1] => 'value'
[fieldname2] => 'value'
)
)
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要回答您的问题,您可以创建所需的数组结构并保存它,方法如下:
请注意:
根据您在上面的评论中所写的内容,您似乎没有遵守 CakePHP 约定。可以这样做,但是如果您决定尽可能坚持 CakePHP 默认值,并且只有在有充分理由时才按照自己的方式进行操作,那么您将为自己节省大量时间和麻烦。
需要记住的几件事是:
id
,而不是followers_id
,并且应在数据库中设置为 PRIMARY KEY 和 AUTO_INCRMENT。如果您决定不遵循惯例,您可能会发现自己摸不着头脑,想知道为什么每一步都不起作用。尝试查看 CakePHP 文档 了解更多详细信息。
To answer your question, you can create the array structure you need, and save it, by doing this:
Please note:
Based on what you've written above in your comments it looks like you're not keeping to the CakePHP conventions. It's possible to do things this way but you'll save yourself a lot of time and trouble if you decided to stick with the CakePHP defaults as much as possible, and only do it your own way when you have a good reason to.
A couple things to remember are:
id
, notfollowers_id
, and should be set as PRIMARY KEY and AUTO_INCREMENT in your database.If you decide not to follow the conventions you'll probably find yourself scratching your head, wondering why things aren't working, every step of the way. Try having a look at the CakePHP documentation for more details.
我认为你需要像下面这样做:
I think you need to do like below: