Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/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_Cakephp_Frameworks_Cakephp 3.0_Cakephp 3.x - Fatal编程技术网

Cakephp-将数据保存到关系模型

Cakephp-将数据保存到关系模型,php,cakephp,frameworks,cakephp-3.0,cakephp-3.x,Php,Cakephp,Frameworks,Cakephp 3.0,Cakephp 3.x,我有三个模型:用户,组和用户组 users table: id | alias | password ... groups table: id | name ... user_groups table: id | user_id (fk users table) | group_id (fk groups table) ... 在我的组控制器中,我接收有关可用组和成员的数据: public function edit($id) { if (!$id) throw new NotFo

我有三个模型:
用户
用户组

users table: id | alias | password ...

groups table: id | name ...

user_groups table: id | user_id (fk users table) | group_id (fk groups table) ...
在我的组控制器中,我接收有关可用组和成员的数据:

public function edit($id)
{
    if (!$id) throw new NotFoundException(__('Unknown Group'));
    //All available groups with members
    $group = $this->Groups->find('all', [
        'contain' => 'Users'
    ]);
    //Only the group + members with the requested id
    $member = $this->Groups->get($id, [
        'contain' => 'Users'
    ]);

    if (!$group) throw new NotFoundException(__('Group does not exist'));
    if ($this->request->is(['post', 'put'])) {
        $this->Groups->patchEntity($group, $this->request->data);
        if ($this->Groups->save($group)) {
            $this->Flash->success(__('Group successfully updated'));
            return $this->redirect(['action' => 'index']);
        }
        $this->Flash->error(__('Failed to update group'));
    }
    $this->set('group', $group);
    $this->set('member', $member);
}
我试图构建一个包含两个
选择框的视图,一个用于已经是组成员的用户,另一个用于剩余(非成员)用户

当涉及到数据保存到关系模型(
用户组
)时,我完全无能为力

我必须使用特定的变量名/输入字段名吗

如何为数据提供服务,以便控制器知道在何处保存数据


提前感谢您,很抱歉提出这些问题,我对整个框架都不熟悉。

Hi您的cakephp版本是什么?嘿,我正在运行3.0.11Hi您的cakephp版本是什么?嘿,我正在运行3.0.11