【问题标题】:cake php: correct url to actioncake php:正确的 url 到行动
【发布时间】:2011-06-29 21:50:23
【问题描述】:

我有两个用于一个操作的 URL,每个 URL 都应该生成不同的视图。

例如: /abc -> 连接控制器 x, action y, view = 0

/def -> 连接控制器 x, action y, view = 1

这很好用

Router::connect('/abc', array('controller' => 'x 'action' => 'y', 'view' => 0));

Router::connect('/def', array('controller' => 'x 'action' => 'y', 'view' => 1));


但现在出现了这个问题:

我有一个公式,它应该将其数据发送到 /def 或 /abc。 如何手动设置,应该使用哪个路由?


编辑:

$form->create('Model', array('url' => array('action' => 'index', 'view' => '1'))); //定义

$form->create('Model', array('url' => array('action' => 'index', 'view' => '0'))); // abc

两者都引导我到 /controller/index 而不是 /def 或 /abc

【问题讨论】:

    标签: forms cakephp routes


    【解决方案1】:
    Router::connect('/def', array('controller' => 'x' action' => 'y', 'view' => 1), array('pass' => array('view')));
    

    然后

    if($this->params['view']){
       // its 1
    } else{
       //its 0
    }
    

    【讨论】:

    • 是的,这对我有用。但是我如何正确选择公式的目标网址?
    • $this->Html->link('foo', '/def');不知道你问什么
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多