Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP表单帮助程序:选择帮助程序不会默认某些自定义字段_Php_Cakephp_Form Helpers - Fatal编程技术网

CakePHP表单帮助程序:选择帮助程序不会默认某些自定义字段

CakePHP表单帮助程序:选择帮助程序不会默认某些自定义字段,php,cakephp,form-helpers,Php,Cakephp,Form Helpers,我对表单选择帮助程序有问题。在我的页面上有两张表格 一种是快速搜索表单。这个使用state\u id。 在URL:state_id:CO中搜索时 这将在下拉列表中自动选择正确的值 但是,当我使用高级表单搜索时。该字段为trail\u state\u id,并且 在URL:trail\u state\u id:CO中 由于某些原因,它不会默认为正确的值。它只是将表单重置为无选择。值被正确地搜索,只是表单帮助器没有识别url中设置了同名的字段。有什么想法吗 <?php class Trail

我对表单选择帮助程序有问题。在我的页面上有两张表格

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

但是,当我使用高级表单搜索时。该字段为trail\u state\u id,并且 在URL:trail\u state\u 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'),
        );
    }

?>
在URL:trail\u state\u 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));
    ?>

使用辅助对象中的第三个参数,可以设置默认值。我是这样做的

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));