Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/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_Arrays_Cakephp - Fatal编程技术网

Cakephp使用数组值添加选项字段

Cakephp使用数组值添加选项字段,php,arrays,cakephp,Php,Arrays,Cakephp,我正在尝试创建一个下拉菜单(选项),为了填充此下拉菜单,我向视图发送了一个数组列表: $country = $this->country_list; $this->set(compact('country')); 现在我的问题是,cake是否有一个内置方法让我使用($this->Form->input())和数组列表的数据来设置输入字段?在控制器中,设置值 $this->set('countries', $this->C

我正在尝试创建一个下拉菜单(选项),为了填充此下拉菜单,我向视图发送了一个数组列表:

            $country = $this->country_list;

            $this->set(compact('country'));

现在我的问题是,cake是否有一个内置方法让我使用(
$this->Form->input()
)和数组列表的数据来设置输入字段?

在控制器中,设置值

$this->set('countries', $this->Country->find('list', array('fields' => 'Country.name')));
在视图中显示下拉框的步骤

$this->Form->input('country_id');
就拿这个例子来说

$sizes = array(
        's' => 'Small',
        'm' => 'Medium',
        'l' => 'Large'
);

echo $this->Form->input('size', array('options' => $sizes, 'default' => 'm'));

只有当他有一个
Country
模型和一个
Country\u id
字段,但他没有提到它时,这才有效。另外:
$this->Country->find(…)
仅适用于CountriesController,但我认为这不是提供的案例,他可以调整它以在他的项目中工作。@BrianKerr感谢您的回复,但是国家列表不在数据库中,只是一个普通的数组列表?