Bonjour,
Je fais actuellement un site web et je reconcontre cette erreur
Model "Post" is not associated with model "User" [CORE\Cake\Model\Behavior\ContainableBehavior.php, line 342]
Voici mon model post :
<?php
class Post extends AppModel{
public $hasMany = array(
'Media' => array(
'dependent' => true
)
);
public $belongsTo = array(
'Category' => array(
'counterCache' => array('post_count' => array('Post.online'=>1))
)
);
public $recursive = -1;
public $validate = array(
'slug' => array(
'rule' => '/^[a-z0-9\-]+$/',
'allowEmpty' => true,
'message' => "L'url n'est pas valide"
),
'name' => array(
'rule' => 'notBlank',
'message' => "Vous devez préciser un titre"
)
);
public $order = 'Post.created DESC, Post.id DESC';
//Permet de generer un brouillon
public function getDraft($type){
$post = $this->find('first',array(
'conditions' => array('online' => -1,'type' => $type)
));
if(empty($post)){
$this->save(array(
'type' => $type,
'online' => -1
),false);
$post = $this->read();
}
$post['Post']['online'] = 0;
return $post;
}
public function afterFind($data, $primary = false){
foreach($data as $k=>$d){
if(isset($d['Post']['slug']) && isset($d['Post']['id']) && isset($d['Post']['type'])){
$d['Post']['link'] = array(
'controller' => Inflector::pluralize($d['Post']['type']),
'action' => 'show',
'id' => $d['Post']['id'],
'slug' => $d['Post']['slug']
);
}
$data[$k] = $d;
}
return $data;
}
public function beforeSave($options = array()){
if(empty($this->data['Post']['slug']) && isset($this->data['Post']['slug']) && !empty($this->data['Post']['name']))
$this->data['Post']['slug'] = strtolower(Inflector::slug($this->data['Post']['name'],'-'));
return true;
}
}
et mon model user :
<?php
class User extends AppModel{
public $validate = array(
'username' => array(
array(
'rule' => 'alphanumeric',
'required' => true,
'allowEmpty' => false,
'message' => "Votre nom d'utilisateur n'est pas valide"
),
array(
'rule' => 'isUnique',
'message' => "Ce nom d'utilisateur est déjà pris"
)
),
'mail' => array(
array(
'rule' => 'email',
'required' => true,
'allowEmpty' => false,
'message' => "Votre email n'est pas valide"
),
array(
'rule' => 'isUnique',
'message' => "Cet email est déjà pris"
)
),
'password' => array(
'rule' => 'notBlank',
'message' => "Vous devez entrer un mot de passe",
'allowEmpty' => false
)
);
}
Pouvez-vous m'aider ?
Merci d'avance !
C'est parce que tu ne lie pas ton model Post au model User.
Après que tu lie les catégories, tu dois lier le model User dans ton model Post