Yii - 自动生成的控制器内部:$id 从哪里来?
一个关于自动生成的 Yii 代码的简单问题:在控制器中,函数如下:
public function actionDelete($id)
它们从哪里获取 $id?是通过 $_POST 或 $_GET 还是完全不同的东西?我正在努力制作一个ajax“删除某些内容”按钮,并且我一直坚持创建一个ajax链接来发布该内容的“id”
a quick question to you about the auto-generated Yii code: in the controller, the functions like this:
public function actionDelete($id)
where do they get that $id from? is it throguh $_POST or $_GET or is it something totally different? I'm struggling to make an ajax 'delete something' button and i'm stuck at creating an ajax link to post the 'id' of that something
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 GET 变量的名称,因此您的操作可能是 /myController/myAction?id=4,这相当于 /myController/myAction/id/4
...并且 4 将是传递给该方法的值。
您可以向该方法添加另一个参数,并且必须在查询字符串中包含该变量/值。
Yii 并不总是有这个,它可能是在 1.12 中添加的。
您可以通过调用 $_GET['id'] 获得相同的值
that is the name of the GET variable, so your action might be /myController/myAction?id=4, which is equivalent to /myController/myAction/id/4
...and 4 would be the value passed to the method.
you can add another parameter to the method, and you will have to include that variable/value in your querystring.
Yii didn't always have this, it was added in 1.12 maybe.
You can get the same value by calling $_GET['id']
这在 Yii 中称为“动作参数绑定”
看一下这个链接,搜索动作参数绑定
http://www.yiiframework.com/doc/guide/1.1/en/basics.controller
This is called "Action Parameter Binding" in Yii
Have a look at this link, search for Action Parameter Binding
http://www.yiiframework.com/doc/guide/1.1/en/basics.controller