Session cakephp会话数据来自两个表

Session cakephp会话数据来自两个表,session,cakephp,Session,Cakephp,一个帐户有andbelongstomy个用户 用户有一个andbelongstomy帐户 帐户有许多模板 属于帐户的模板 帐户无法登录,用户可以代表帐户登录和操作。用户为帐户创建模板,我的数据库的问题是模板需要帐户id,以便该帐户雇用的其他用户可以访问该模板,但我遇到的问题是,cake无法找到与该用户相关的帐户id并将其放入模板表中 相关表格如下: 用户-id、名称、地址 帐户-id、公司名称、荷兰银行 帐户用户-id,用户id,帐户id 模板-id、名称、描述 function add()

一个帐户有andbelongstomy个用户

用户有一个andbelongstomy帐户

帐户有许多模板

属于帐户的模板

帐户无法登录,用户可以代表帐户登录和操作。用户为帐户创建模板,我的数据库的问题是模板需要帐户id,以便该帐户雇用的其他用户可以访问该模板,但我遇到的问题是,cake无法找到与该用户相关的帐户id并将其放入模板表中

相关表格如下:

用户-id、名称、地址 帐户-id、公司名称、荷兰银行 帐户用户-id,用户id,帐户id 模板-id、名称、描述

 function add() {
        $this->set('title_for_layout', 'Please Enter Your Temaplate Details');
        $this->set('stylesheet_used', 'style');
        $this->set('image_used', 'eBOXLogo.jpg');  

        if($this->request->is('post')){ $accounts=$this->User->find('all', array('f' => array('Account.companyName'), 'conditions' => array('User.id' => $this->Auth->user('id')), 'contain' => array('accountsuser.user_id')));
    $this->Template->create();

          if ($this->Template->save($this->request->data)) {
            $this->Session->setFlash('The template has been saved');
            $this->redirect( array('controller' => 'Fields','action' => 'add'));
          } else {
            $this->Session->setFlash('The template could not be saved. Please, try again.');
          }
        }

        $this->set('accounts', $accounts); 

     }
模板视图

<h2>Please enter the details of your Template</h2></br>
<p>After Hitting Submit You Can Start Adding Various Fields</p>

<?php
echo $this->Form->create('Template', array('action'=>'add'));
echo $this->Form->input('name',array('label'=>'Template Name: '));
echo $this->Form->input('account_id',array('label'=>'Business: ', 'type' => 'select', 'options' => $accounts));
echo $this->Form->input('description',array('label'=>'Short Description Of Template: '));
echo $this->Form->end('Click Here To Submit Template');
?>

你试过递归吗

在模板控制器中:

$this->User->recursive = 2; //now you will get businesses related to the users
$current_user = $this->User->findById($id_of_the_user); //find the current user
$this->set('current_user', $current_user);
在模板视图中:

<?php
echo $this->Form->create('Template', array('action'=>'add'));
echo $this->Form->input('name',array('label'=>'Template Name: '));
echo $this->Form->input('description',array('label'=>'Short Description Of Template: '));
echo $this->Form->input('business_id', array('type' => 'hidden', 'value' => $current_user['Business']['id']));
echo $this->Form->end('Click Here To Submit Template');
?>

如果您不知道$current\u用户的内部内容,请将
放入

<?php
echo $this->Form->create('Template', array('action'=>'add'));
echo $this->Form->input('name',array('label'=>'Template Name: '));
echo $this->Form->input('description',array('label'=>'Short Description Of Template: '));
echo $this->Form->input('business_id', array('type' => 'hidden', 'value' => $current_user['Business']['id']));
echo $this->Form->end('Click Here To Submit Template');
?>