Categorie
Information and Communications Technology

How to hide fields in CakePHP 2.0 scaffolding views

This is a simple code to hide fields in scaffolding views. In the controller add the method beforeRender in this way:

    public function beforeRender() {
        $action = $this->request->params['action'];
        
        if ($action == 'index') {
            $fields =  array('id', 'username', 'role', 'created', 'email'); //'password','modified'
            $this->set('scaffoldFields', $fields);
        } else if ($action == 'view') {
            $fields =  array('id', 'username', 'role', 'created', 'modified', 'email'); //'password'
            $this->set('scaffoldFields', $fields);
        }
        
        return parent::beforeRender();
    }

in this example the fields were changed in the index and view actions, but in the other actions the fields are displayed all.
 

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *