我剛剛開始學習CakePHP,並開始使用官方博客教程。到目前爲止這麼好,但我沒有得到當前和修改的時間節省數據庫,因爲既不在視圖中,也不在控制器中有任何指向這些字段的行。在CakePHP的博客教程中,當前和修改時間如何保存?
這裏是加PostsController.php代碼:
public function add()
{
if($this->request->is('post'))
{
$this->Post->create();
if($this->Post->save($this->request->data))
{
$this->Session->setFlash(__('Your post has been saved.'));
return $this->redirect(array('action' => 'index'));
}
else
{
$this->Session->setFlash(__('Unable to add your post.'));
}
}
}
這裏是視圖代碼add.ctp:
<!-- File: /app/View/Posts/add.ctp -->
<?php echo $this->Html->link('Home', 'index/home'); ?>
<h1>Add Posts</h1>
<?php
echo $this->Form->create('Post');
echo $this->Form->input('title');
echo $this->Form->input('body', array('rows' => '3'));
echo $this->Form->submit('Add Post', array('name' => 'add_post'));
//echo $this->Form->end('Save Post');
?>
所以,有人請告訴我哪行被保存當前的時間?非常感謝您的幫助。
謝謝你本。你正確回答了我的疑問。再次感謝。 –