0

I have an application in which we give a very friendly interface for managing data. This is done through many controllers' add/edit/view functions. But now the requirement has come that we should have "super admins" able to edit anything, and scaffolding will give them a quick and dirty manner of changing data. Since scaffolding uses add/edit/view by default, I've unintentionally overwritten the ability to scaffold.

I can't just go and change all my calls to edit/add for our "user friendly" data managing. So I want to essentially ignore the add/edit/view when, for example, a user has a flag of "yes, please let me scaffold". I imagined it would be something like:

    public function edit($id) {
        if (admin_user) {        
            $scaffold;
        } else {
            [user-friendly version code]
        }
    }

But no dice. How can I achieve what I want?

4

1 回答 1

1

假设您已经有管理员用户并且您只想构建超级用户:

还假设您将有关是否成为超级用户的信息存储在表中命名的列superusers

在你的 core.php

Configure::write('Routing.prefixes', array('admin', 'super));

在你的 appController

public $scaffold = 'super';

beforFilter() {
    if($this->Auth->user('super') && !isset($this->params['super'])
        $this->redirect(array('super' => true));
}

现在我不能尝试这段代码,但这个想法应该可行。

编辑:我们需要检查我们是否已经在 super_action 以避免无限重定向

于 2013-09-28T07:07:21.363 回答