Bonjour, j'ai les pattes dans CakePHP tout se passe bien, mais j'ai un beforeSave() qui permet de me faire un slug et celui-ci retourne NULL s'il voit un accent.
Mon beforeSave() /Model/Post.php :
<?php
public function beforeSave($options = array()) {
$this->data$this->alias]'slug'] = Inflector::slug(strtolower($this->data$this->alias]'name']), '-');
return true;
}
?>
Mon PostController.php :
<?php
public function add(){
if(isset($this->request->data'Post'])) {
$this->Post->create();
$this->Post->save(array(
'name' => $this->request->data'Post']'name'],
'content' => $this->request->data'Post']'content']
), true, array('name', 'slug', 'content'));
}
}
?>
Mon add.ctp qui ne vous servira à rien :D
<h1>Ajouter un Post</h1>
<?= $this->Form->create('Post'); ?>
<?= $this->Form->input('name', array(
'label' => 'Titre',
)); ?>
<?= $this->Form->input('content', array(
'label' => 'Article',
'style' => 'height: 200px;'
)); ?>
<?= $this->Form->end(array('label' => 'Ajouter', 'class' => 'button')); ?>
Donc quand j'ajoute un name sans accent il ne me dit rien et fait l'ajout correctement. Et quand il y a un accent il gueule :
Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'slug' cannot be null
SQL Query: INSERT INTO cake.posts (name, content, created, slug) VALUES ('ô lol', 'zefzef', '2013-03-27 10:29:50', NULL)
Merci pour vos lumières :) .