Does anybody see what I’m doing wrong?
The $brand['slug'] is empty when saving so i guess something is going wrong in the find query.
Thanks in advance.
public function beforeSave() {
if (isset($this->data['Smartphone']['model'])) {
$brand = $this->Brand->find('first', array(
'conditions' => array(
'Brand.id' => $this->data['Smartphone']['brand_id']
)
));
$this->data['Smartphone']['slug'] = $brand['slug'].'-'.Inflector::slug(strtolower($this->data['Smartphone']['model']), '-');
}
return true;
}
What it looks, I think you should use
$brand['Brand']['slug']instead of$brand['slug'].You can try to print $brand array using
pr($brand);just after the find query you have written. And provide the array index accordingly.