Cakephp插件过滤器重命名选择

时间:2013-03-27 11:33:32

标签: php cakephp plugins cakephp-2.1

我从https://github.com/lecterror/cakephp-filter-plugin安装了一个插件过滤器。

如何重命名下拉栏中的值?

现在我可以选择:

[ ]
[0]
[1]

我需要的是:

[ ]
[Agent]
[Investor]

public $filters = array(
    'index' => array(
        'Model' => array( 
            'Model.Tablename' => array('label' => 'Find'),
            'Model.Tablename' => array(
                'label' => 'Position type',
                'type' => 'select',
                'selectOptions' => array (
                    0 => 'Agent',
                    1 => 'Investor'
                )
            )
        )
    )
);

在选择器类型中,我想将0重命名为Agent,将1重命名为Investor。

1 个答案:

答案 0 :(得分:0)

自己找:

// plugincode -----> filter_form_fields

  foreach ($viewFilterParams as $field) {
        // Edited on  28-03-2013 
        // check if option type is select.
        if ($field['options']['type'] == "select") {
            // check for all option values ( 0,1,2,3,4 ect ) and rename it with optionNewValue
            foreach ($field['options']['options'] as $optionvalue) {
                $optionNewValue = $field['options']['OptionKey'][$optionvalue];
                // Rename the optionvalue
                $field['options']['options'][$optionvalue] = $optionNewValue;
            }
        }

// filtercomponent.ctp add(插件代码)

  

// Optionkey给出值filter_form_fields                           //在控制器内使用Optionkey => array()重命名值                           $ options ['OptionKey'] = $ settings ['OptionKey'];

现在你可以放入控制器

'index' => array(
        'Model' => array( 
            'Model.Tablename' => array('label' => 'Find'),
            'Model.Tablename' => array(
                'label' => 'Position type',
                 'type' => 'select',
                'OptionKey' => array (
                    0 => 'agent',
                    1 => 'investor'

            )
        )
    )
);

:d:d:d:d:d