Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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:如何将项目列表合并为一个列表_Cakephp - Fatal编程技术网

Cakephp:如何将项目列表合并为一个列表

Cakephp:如何将项目列表合并为一个列表,cakephp,Cakephp,伙计们,我有一个代码,它在不同的数组中列出不同的项,但问题是我希望这些项现在显示在单个选择选项上。当前我的代码只在选择选项上显示一个项,当我调试它时,它会显示所有内容。如何使我的选择选项显示所有项。数组包含一个表中的数据 我的代码是 $list=$this->ProgrammeChoice->Programme->ProgrammeRequirementsSubject->find('list', array('fields'=> a

伙计们,我有一个代码,它在不同的数组中列出不同的项,但问题是我希望这些项现在显示在单个选择选项上。当前我的代码只在选择选项上显示一个项,当我调试它时,它会显示所有内容。如何使我的选择选项显示所有项。数组包含一个表中的数据

我的代码是

   $list=$this->ProgrammeChoice->Programme->ProgrammeRequirementsSubject->find('list',
             array('fields'=> array('programme_code','programme_name'),
                   'conditions'=>array('subject_code'=>$s_code,
                                'compulsory'=>'true')));
在我看来,选择选项的代码是

echo $this->Form->select("ProgrammeChoice.programme_code.2",$list);
它只显示一个选择选项,但我希望所有选项都可用

好的,当我回显上面的数组i.e$list时,它会一分为二,结果如下

array(
    'BACC' => 'Bachelor of Accountancy'
)

array(
    'HEN' => 'Electrical Engineering'
)
但是我想要一个数组,用于两个课程,比如

 array(
    'BACC' => 'Bachelor of Accountancy'
        'HEN' => 'Electrical Engineering'

    )

我该怎么做。

这行吗?我添加了一些行来合并不同的阵列

$list=$this->ProgrammeChoice->Programme->ProgrammeRequirementsSubject->find('list',
  array('fields'=> array('programme_code','programme_name'),
  'conditions'=>array('subject_code'=>$s_code,
  'compulsory'=>'true')));

/* Merge array */
$result = array();
foreach ($list as $l) {
  $result = array_merge ($result, $l);  
}
$list = $result;

echo $this->Form->select("ProgrammeChoice.programme_code.2",$list);

你真的需要更具体一些。如何获得这两个阵列?它们是否包含来自两个单独表的数据?数据是否在同一个表中,但有不同的数据?好的,thanx我添加了信息这很奇怪,Cake应该为您提供层次结构中最高模型及其关联模型的数据。如何使用返回1个数组的操作获得2个数组?它们是否包含在一个更大的数组中?您的最后一个示例是它们应该如何出现。您可以尝试在条件和字段中指定完整的
Model.field\u name
,并设置选项
'recursive'=>-1
。这是一个糟糕的解决方案,如果数组非常大,此操作可能需要很长时间,甚至永远不会完成。@8vius:它用于选择框。如果它们那么大,整个UI可能需要使用ajax和autocompletion重做。