我是cakephp的新手,我有这样的困难:
从这个SQL查询开始:
select service_group.name as service_group_name, service_group.id as service_group_id, campaign.name as campaign_name, campaign.id as campaign_id
from group_service
join group_service_campaign on group.service.id = group_service_campaign.group_service_id
join campaign on group_service_campaign.campaign_id = campaign.id
where campaign.active = 'Y'
and campaign.id in ($in)
and campaign.company_id = ${_SESSION['companyId']}
order by group_service.name, campaign.name
我在控制器中将其转换为此内容:
$var_campaign = $this->loadModel('Service_Group');
$var_campaign = $this->Group_Service->find('list', ['keyfield' => 'campaign_id', 'valueField' => 'campaign_name', 'groupField' => 'service_group_name'])
->join(['table' => 'service_group_campaign',
'type' => 'inner',
'conditions' => 'Service_Group.id = service_group_campaign.service_group_id'
])
->join(['table' => 'campaign',
'type' => 'inner',
'conditions' => 'service_group_campaign.campaign_id = campaign.id'
]);
$var_campaign->where(['campaign.active' => 'Y']);
$var_campaign->order(['grou_service.name,campaign.name']);
我很难用这个来创建一个带有optgroup的select表单元素。 我搜索的示例和问题类似,但我尝试过的都没有工作。
我的观点:
echo $this->Form->create();
echo $this->Form->input('id', array('label' => 'Services :', 'type' => 'select', 'empty'=> '-- Select --', 'options' => $var_campaign));
echo $this->Form->select("field", $var_campanha);
echo $this->Form->end();
当我在查询语句中使用find(' list' ...)时,我得到一个空白的回复,如果我使用find(' all' ...)我得到一个没有完整的回复,因为所有的广告系列名称都没有回复,只有服务组名称带有他们的ID。
我的optgroup显示如下纯文本:
{" id":-1," name":" Active Proposals"," mod":" W&# 34;," company_id":10}
等等。
我哪里出错?
提前感谢。