سؤال

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?

هل كانت مفيدة؟

المحلول

suppose you already have admin users and you want to scaffold only super-user:

Also suppose you store the information about beeing a super-user or not in a column named super in the users table

in your core.php

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

in your appController

public $scaffold = 'super';

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

Now I can't try this code but the idea should work.

edit: we need to check if we are already in a super_action to avoid infinite redirect

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top