/** * beforeValidate is called before a model is validated, you can use this callback to * add behavior validation rules into a models validate array. Returning false * will allow you to make the validation fail. * * @param Model $model Model using this behavior * @param array $options Options passed from Model::save(). * @return mixed False or null will abort the operation. Any other result will continue. * @see Model::save() */ public function beforeValidate(Model $model, $options = array()) { //ページデータをセット $referencePageId = $model->getReferencePageId($model->data); $fields = array('room_id', 'permalink'); $targetPage = $model->findById($referencePageId, $fields); if (empty($targetPage)) { return false; } $model->data['Page']['room_id'] = Current::read('Room.id'); $slug = $model->data['Page']['slug']; if (!isset($slug)) { $slug = ''; } $model->data['Page']['slug'] = $slug; $permalink = ''; if (strlen($targetPage['Page']['permalink']) !== 0) { $permalink = $targetPage['Page']['permalink'] . '/'; } $permalink .= $slug; $model->data['Page']['permalink'] = $permalink; $model->data['Page']['is_published'] = true; $model->data['Page']['is_container_fluid'] = false; return parent::beforeValidate($model, $options); }