donglang1976 2010-05-07 09:30
浏览 28
已采纳

CakePHP中的自定义数据表单

I'm building a controller to manage group based ACL in CakePHP and when I create or edit a group I want to be able to select what permissions it has. The group data table only stores a group ID and a group Name as the permissions are stored in the ACO/ARO table.

I have an array from the ACO that I want to turn into a set of checkboxes so you can check them to allow access from that group to that ACO. So first off, how do I turn this array into a set of checkboxes. The array looks like this:

array(
    [0] => array(
        [Aco] => array(
            [alias] => 'alias'
            [id] => 1)
        [children] => array (
            [0] => array(
                [Aco]=>
            ...etc  
    ))
    [1] => array(
        ...etc
)

My next question is how can I check these once the form has been submitted to the controller to allow the selected actions?

[Update] Ok changing the angle of my question, how can I use the Form helper to create forms that are not based on any Model?

  • 写回答

1条回答 默认 最新

  • douzhang5121 2010-05-07 18:21
    关注

    You may want to check PoundCake Control Panel (for CakePHP 1.2) - take a look at the screenshots. The functionality you want is present there but radio inputs are used instead of checkboxes. Users and Groups are linked to ACOs. So, changing Users or Groups tree structure you change the tree structure of ACOs. Menu items are linked to AROs. So, changing the tree structure of menus you change the tree structure of AROs.

    For example, in groups_controller.php:

    public function permissions($id = null){
        $this->_checkIdPresence($id);
        if(!empty($this->data)){
            $aroNode = array('model' => 'Group', 'foreign_key' => $this->data['Group']['id']);
            foreach($this->data['Acos'] as $aco){
                if(!empty($aco['permission'])){
                    $do = '';
                    if($aco['permission'] == '1'){
                        $do = 'allow';
                    }elseif($aco['permission'] == '-1'){
                        $do = 'deny';
                    }
                    $acoNode = array('model' => $aco['model'], 'foreign_key' => $aco['foreign_key']);
                    if($this->Acl->{$do}($aroNode, $acoNode, '*')){
                        $message = sprintf(__('<i>%s</i> permission to <i>%s</i> has been saved.', true),ucfirst($do), $aco['name']);
                        $this->_flash($message, 'success');
                    }else{
                        $message = sprintf(
                            __('<i>%s</i> permission to <i>%s</i> could not be saved. Please, try again.', true),
                            ucfirst($do), $aco['name']
                        );
                        $this->_flash($message, 'error');
                    }
                }
            }
        }
        // Get ARO for the current Group and all related ACOs from the db
        $this->data = $this->Group->read(null, $id);
        $acosTree = $this->ControlPanel->checkPermissions($id);
        $existingPermissions = $this->ControlPanel->findRecordedPermissions($id);
        $this->set(compact('acosTree', 'existingPermissions'));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办