Domanda

In my Menu model I'm trying to fill the slug field if the user didn't fill it.

Model/Menu.php

    public function beforeSave($options = array()){
            if(
                isset($this->data[$this->alias]['name']) && 
                !isset($this->data[$this->alias]['slug'])
            ){
                     //than fill the slug field in the db for the user.
                $this->data[$this->alias]['slug'] = strtolower(Inflector::slug($this->data[$this->alias]['name'], '-'));
            }
        }//end function

but it doesn't work all the data are saved without going throught this method.

È stato utile?

Soluzione

It's not going through that method at all. If it was, it would not save, since you didn't return true; per the instructions in the CakePHP Book.

You're likely saving Menu data through an association of another model - in which case, it would use IT'S beforeSave, not this one.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top