dou91855 2010-05-27 12:46
浏览 105
已采纳

如何从cakePHP中获取URL到模型的参数?

let's say i have:

http://some-domain/application/controller/action/parameter

This is somehow working in cakePHP. Now I want to now what exactly 'parameter' is. But inside the Model. How to get to this information?

I have to say that there is a formular including a 'Next' Button and I want to validate the input inside of the Model in beforeValidate(). But I have to know on which page the user was at the time of clicking the submit button. This page is 'parameter'.

  • 写回答

3条回答 默认 最新

  • douping6871 2010-05-27 14:26
    关注

    There are two type of parameter in CakePHP, you have passed parameters and named parameters. A passed parameter is as shown in your example and will be passed as part of the url.

    http://example.com/controller/action/passed_param
    echo $this->params['passed'][0] // 'passed_param'
    
    http://example.com/controller/action/name:param
    echo $this->params['named']['name'] // 'param'
    

    I would recommend getting the parameters in your controller and calling model methods with them passed through.

    Such as

    $this->Model->find('all', array('conditions'=>array('id'=>$this->params['passed'][0])));
    

    As to how it's working, you will want to have a look at your routes file. In your app/config/routes.php you will find all the routing and which parts are passed.

    The standard cake url format is usually as follows, as you'll see in the routes. array('controller'=>'MyController', 'action'=>'MyAction', 'MyParam');

    I can't seem to find a specific page in the book on Params, but have a google around for guides.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记