我是 cakePHP 的新手,我已经着手创建一个非常小的“状态报告”项目,这将允许用户报告他们被分配到的项目的当前状态。
我目前正在使用 acl、auth 和 session 组件来允许多层用户相互管理,而管理员则可以创建用户、项目并将它们相互分配。我还修复了它,以便当用户登录并添加“状态”时,他们的登录会话会自动处理状态的“user_id”:
$this->data['Status']['user_id'] = $this->Auth->user('id');
我现在需要帮助的是过滤用户可以选择添加“状态”的项目选项。
我目前有一个表,其中包含用户和名为 *projects_users* 的项目之间的关系,其中 *id、project_id、user_id* 作为字段。但是,在烘焙此设置后,当用户添加“状态”时,下拉菜单会提供所有项目,而不是严格地“分配给”的项目。
我想过滤用户对他们分配到的项目的选项。我是否应该建立更多的关系,或者这是一个非常容易编写的小函数?任何帮助将不胜感激,如果我遗漏了信息,我很乐意发布任何其他信息。
这是状态模型设置:
class Status extends AppModel {
var $name = 'Status';
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Project' => array(
'className' => 'Project',
'foreignKey' => 'project_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
我的用户模型如下所示:
var $belongsTo = array(
'Group' => array(
'className' => 'Group',
'foreignKey' => 'group_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $hasMany = array(
'Status' => array(
'className' => 'Status',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
var $hasAndBelongsToMany = array(
'Project' => array(
'className' => 'Project',
'joinTable' => 'projects_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'project_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);