【问题标题】:turn off cakephp routing inside a form关闭表单内的 cakephp 路由
【发布时间】:2013-06-11 17:10:32
【问题描述】:
echo $this->form->create('Cost', array('action' => 'add'));

        echo $this->form->inputs(array(
            'legend' => false,
            'cost_type_id' => array(
                'class' => 'span-8',
                'options' => $cost_types
            )
        ));

        echo $this->html->tag(
            'div',
            $this->form->button(
                sprintf('%s %s',
                    $this->html->image('icons/silk/application_add.png'),
                    __('Create new Cost', true)
                ),
                array(
                    'title' => sprintf('Add')
                )
            ),
            array('class' => 'buttons clearfix')
        );
        echo $this->form->end();

我有一个路由前缀集,它会自动将此表单发送到

/prefix/costs/add

有没有办法可以在form->createform->button 中将其关闭?

【问题讨论】:

    标签: php cakephp url-routing cakephp-1.3


    【解决方案1】:

    像这样定义你要提交表单的路径

    echo $this->Form->create('Cost', array(
        'url' => array('prefix'=>null, 'controller' => 'costs', 'action' => 'add')
    ));
    

    PS:像任何其他路由数组一样更改 url 数组以满足您的需求。

    参考:docs

    【讨论】:

    • 我刚试过这个,它会重定向到页面,但不会“发布”表单中的数据?这是一个单独的问题吗?有什么想法吗?
    • 这是一个单独的问题,但是从我可以从您的代码中推断出,您有一个与 $this->Form->end 没有直接关系的添加按钮,因此您有一个 js 提交形式?
    猜你喜欢
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多