我有三张桌子campaign_social_accounts
,social_accounts
和social_networks
SocialNetworks
contains 是用户可以通过列连接到的网络
+-----+--------+
| id | title |
+-----+--------+
SocialAccounts
让所有帐户用户与列连接为
+----+---------+-------------------+--------------+----------+
| id | user_id | social_network_id | access_token | user_key |
+----+---------+-------------------+--------------+----------+
CampaignSocialAccounts
与该活动关联Campaigns
并添加了社交帐户
+-----+-------------+-------------------+
| id | campaign_id | social_account_id |
+-----+-------------+-------------------+
我希望用户从中进行选择add()
,这就是我在控制器中所做的CampaignSocialAccounts
SocialAccounts
$socialAccounts = $this->CampaignSocialAccounts->SocialAccounts->find('list', [
'conditions' => [
'user_id' => $this->Auth->user('id')
]
]);
和add.ctp
echo $this->Form->control('social_account_id', ['options' => $socialAccounts]);
问题
这显示id
在列表中,因为该字段中没有其他列可以设置为displayField()
另外,我想显示列表有点像
Facebook(112233445566)
Youtube(2233112233)
Where Facebook
and Youtube
are title from SocialNetworks
table and (112233....)
is user_key
fromSocialAccounts
并且生成的选项的值将id
是SocialAccounts
<option value="1<id from social_accounts>">Facebook(112233445566)</option>
<option value="2<id from social_accounts>">Youtube(2233112233)</option>
是否有可能,如果是,那么最好和最简单的方法是什么。
编辑 2:我的尝试
在控制器动作中
$socialAccounts = $this->CampaignSocialAccounts->SocialAccounts
->find('list', ['valueKey' => 'social_account_title'])
->contain(['SocialNetworks'])
->where(['user_id' => $this->Auth->user('id')]);
SocialAccount.php 实体
public function _getSocialAccountTitle()
{
if (isset($this->social_network)) {
return $this->social_network->title.' ('.$this->user_key.')';
}
return $this->id;
}
还是没有效果