【问题标题】:CakePHP Form Helper: Select helper is not defaulting certain custom fieldsCakePHP 表单助手:选择助手没有默认某些自定义字段
【发布时间】:2011-09-06 18:57:24
【问题描述】:

我在使用表单选择助手时遇到问题。在我的页面上,我有两个表单。

一个是快速搜索表单。这个使用 state_id。 在 URL 中搜索时:state_id:CO 这将在下拉列表中自动选择正确的值。

但是,当我使用高级表单进行搜索时。该字段是 trail_state_id 和 在 URL 中:trail_state_id:CO 由于某种原因,它不会将其默认为正确的值。它只是将表单重置为无选择。这些值被正确搜索,只是表单助手没有识别出在 url 中设置了同名的字段。有什么想法吗?

<?php 
class Trail extends AppModel {
    public $filterArgs = array(
        array('name' => 'state_id','field'=>'Area.state_id', 'type' => 'value'),
        array('name'=>'trail_state_id','field'=>'Area.state_id','type'=> 'value'),
        );
    }

?>

在网址中:trail_state_id:CO

<?php
    echo '<h4>State*:</h4><div>'.$this->Form->select('trail_state_id', $stateSelectList, null, array('style'=>'width:200px;','escape' => false,'class'=> 'enhanced required','empty'=> false));
    ?>

【问题讨论】:

    标签: php cakephp form-helpers


    【解决方案1】:

    使用帮助程序中的第三个参数,您可以设置默认值。我是通过以下方式做到的;

    echo '<h4>State*:</h4><div>'.$this->Form->select('trail_state_id', $stateSelectList, (empty($this->params['named']['trail_state_id']) ? null: $this->params['named']['trail_state_id']), array('style'=>'width:200px;','escape' => false,'class'=> 'enhanced required','empty'=> false));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 2012-11-15
      • 2011-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-16
      相关资源
      最近更新 更多