2
votes

I'm learning CakePHP and I follow this tuto: http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html

I'm working with CakePHP 2.2.3.

Well, I arrived where I have to add groups and users. But, I've not the name of my groups in my database...

Can you help me?

GroupesController:

    <?php
    class GroupesController extends AppController{

    function add(){
    if (!empty($this->data)) {
            if ($this->Groupe->save($this->data)) {
                $this->flash('Votre groupe a été sauvegardé.','/groupes');
            }
        }
    }
    function beforeFilter(){
        parent::beforeFilter();
        $this->Auth->allow('*');
    }
  }
    ?>

Model:

<?php
class Groupe extends AppModel{
    public $actsAs=array('Acl'=>array('type'=>'requester'));
    var $validate = array(
    'nom' => array(
    'rule' => array('minLength', 1)
    )
    );
    public function parentNode(){
        return null;
    }
}
?>

View:

<h1>Ajouter un groupe</h1>
    <?php
        echo $this->Form->create('groupes');
        echo $this->Form->input('nom');
        echo $this->Form->end('Sauvegarder le groupe');
    ?>
1

1 Answers

0
votes

I think you do not get the data because the form in your view is not correctly created. It should be the name of the model:

echo $this->Form->create('Groupe');

To see what data are posted to your add action, you could also use the debug() function:

function add(){
    debug($this->data);
    ...
}

or for Cake 2

function add(){
    debug($this->request->data);
    ...
}

also you can add an else after the call to save() to debug any validation errors:

if ($this->Groupe->save($this->data)) {
  $this->flash('Votre groupe a été sauvegardé.','/groupes');
}
else{
    debug($this->Groupe->validationErrors);
}