如何自动接收方法中的变量?
是否可以定义如下方法来接收 $id ?
public function action_delete($id){
}
我已经定义了一条路线
Route::set('tweet', 'tweet/delete/<id>', array('id' => '\d+'))->defaults(array(
'controller'=>'tweet',
'action'=>'delete'
));
,我记得几个月前类似的代码片段...
更新:我收到以下错误消息
Missing argument 1 for Controller_Tweet::action_delete()
Is it possible to define a method like below to receive $id?
public function action_delete($id){
}
I've defined a route
Route::set('tweet', 'tweet/delete/<id>', array('id' => '\d+'))->defaults(array(
'controller'=>'tweet',
'action'=>'delete'
));
I remember a code snippet something like this few months ago...
Updated: I get the following error message
Missing argument 1 for Controller_Tweet::action_delete()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Kohana 3.2 中,这不再起作用。您必须通过
以下方式检索变量: http://kohanaframework.org/3.2/指南/api/Request#param
In Kohana 3.2, this doesn't work anymore. You'll have to retrieve the variable through
See: http://kohanaframework.org/3.2/guide/api/Request#param
如果您的 Kohana 版本 < 3.2 那么你可以使用它,但是强烈建议你使用
$this->request->param('id')
->; 获取 id 值这是3.2版本以来唯一的方法:If your Kohana version < 3.2 then you can use this, however it is highly recommended that you get the id value with
$this->request->param('id')
-> this is the only way since 3.2 version: