【问题标题】:How to receive a variable in method automatically?如何自动接收方法中的变量?
【发布时间】:2011-12-09 20:33:29
【问题描述】:

是否可以定义如下方法来接收 $id?

public function action_delete($id){

}

我已经定义了一条路线

Route::set('tweet', 'tweet/delete/<id>', array('id' => '\d+'))->defaults(array(
    'controller'=>'tweet',
    'action'=>'delete'
));

我记得几个月前有一个类似这样的代码 sn-p...

更新:我收到以下错误消息

Missing argument 1 for Controller_Tweet::action_delete()

【问题讨论】:

    标签: variables methods kohana


    【解决方案1】:

    如果您的 Kohana 版本 $this->request->param('id') 获取 id 值 -> 这是自 3.2 版本以来的唯一方法:

    public function action_delete(){
       $id = $this->request->param('id');
       // Rest of tour code
    }  
    

    【讨论】:

    • // 啊...我使用的是 3.2 ..这就是它无法正常工作的原因。谢谢你的信息。
    • stackoverflow 怎么会删除@matino?
    【解决方案2】:

    在 Kohana 3.2 中,这不再起作用。您必须通过

    检索变量
    $id = $this->request->param('id');
    

    见:http://kohanaframework.org/3.2/guide/api/Request#param

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-20
      • 2020-01-11
      • 1970-01-01
      • 2020-10-05
      • 1970-01-01
      • 2013-01-25
      • 1970-01-01
      相关资源
      最近更新 更多