0
我是一個cakephp新手:D在保存到數據庫之前修改數據
如何在cakephp將數據放入mysql之前修改控制器中的數據?
function add() {
if (!empty($this->data)) {
$this->Template->create();
/* This works! */
$this->data['Template']['slug'] = Inflector::slug(utf8_encode(strtolower($this->data['Template']['name'])),'-');
/* does not work ! */
$this->data['Template']['created'] = time();
$this->data['Template']['category_id'] = $this->data['Template']['category'];
if ($this->Template->save($this->data)) {
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action' => 'index'));
}
}else{
/* dropdown */
$this->set('categories',$this->Template->Category->find('list'));
}
}
場在我的數據庫:
模板
- ID
- 塞
- CATEGORY_ID(屬於類別)
- 名
- 已創建
任何人都可以幫助我嗎?
問候!