CakePHPにてmodifiedが正しく表示されません。
最近CakePHPの勉強を始めた者です。
早速エラーに苦しめられています。。。。
初歩的な問題かと思いますので、
どなたかお分かりの方、ご回答宜しくお願い致します。
【index.ctp】と【TopicsController】【Topic.php】のソースを記載します
index.ctp
<div class="topics index">
<h2><?php echo __('Topics'); ?></h2>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th><?php echo $this->Paginator->sort('id'); ?></th>
<th><?php echo $this->Paginator->sort('title'); ?></th>
<th><?php echo $this->Paginator->sort('body'); ?></th>
<th><?php echo $this->Paginator->sort('category_id'); ?></th>
<th><?php echo $this->Paginator->sort('created'); ?></th>
<th><?php echo $this->Paginator->sort(' modified'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($topics as $topic): ?>
<tr>
<td><?php echo h($topic['Topic']['id']); ?> </td>
<td><?php echo h($topic['Topic']['title']); ?> </td>
<td><?php echo h($topic['Topic']['body']); ?> </td>
<td>
<?php echo $this->Html->link($topic['Category']['name'], array('controller' => 'categories', 'action' => 'view', $topic['Category']['id'])); ?>
</td>
<td><?php echo h($topic['Topic']['created']); ?> </td>
<td><?php echo h($topic['Topic']['modified']); ?> </td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('action' => 'view', $topic['Topic']['id'])); ?>
<?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $topic['Topic']['id'])); ?>
<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $topic['Topic']['id']), array(), __('Are you sure you want to delete # %s?', $topic['Topic']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
));
?> </p>
<div class="paging">
<?php
echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
echo $this->Paginator->numbers(array('separator' => ''));
echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
?>
</div>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('New Topic'), array('action' => 'add')); ?></li>
<li><?php echo $this->Html->link(__('List Categories'), array('controller' => 'categories', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Category'), array('controller' => 'categories', 'action' => 'add')); ?> </li>
<li><?php echo $this->Html->link(__('List Comments'), array('controller' => 'comments', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Comment'), array('controller' => 'comments', 'action' => 'add')); ?> </li>
</ul>
</div>
TopicsController
<?php
App::uses('AppController', 'Controller');
/**
* Topics Controller
*
* @property Topic $Topic
* @property PaginatorComponent $Paginator
*/
class TopicsController extends AppController {
/**
* Components
*
* @var array
*/
public $components = array('Paginator');
/**
* index method
*
* @return void
*/
public function index() {
$this->Topic->recursive = 0;
$this->set('topics', $this->Paginator->paginate());
}
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
if (!$this->Topic->exists($id)) {
throw new NotFoundException(__('Invalid topic'));
}
$options = array('conditions' => array('Topic.' . $this->Topic->primaryKey => $id));
$this->set('topic', $this->Topic->find('first', $options));
}
/**
* add method
*
* @return void
*/
public function add() {
if ($this->request->is('post')) {
$this->Topic->create();
if ($this->Topic->save($this->request->data)) {
$this->Session->setFlash(__('The topic has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The topic could not be saved. Please, try again.'));
}
}
$categories = $this->Topic->Category->find('list');
$this->set(compact('categories'));
}
/**
* edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function edit($id = null) {
if (!$this->Topic->exists($id)) {
throw new NotFoundException(__('Invalid topic'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->Topic->save($this->request->data)) {
$this->Session->setFlash(__('The topic has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The topic could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('Topic.' . $this->Topic->primaryKey => $id));
$this->request->data = $this->Topic->find('first', $options);
}
$categories = $this->Topic->Category->find('list');
$this->set(compact('categories'));
}
/**
* delete method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function delete($id = null) {
$this->Topic->id = $id;
if (!$this->Topic->exists()) {
throw new NotFoundException(__('Invalid topic'));
}
$this->request->allowMethod('post', 'delete');
if ($this->Topic->delete()) {
$this->Session->setFlash(__('The topic has been deleted.'));
} else {
$this->Session->setFlash(__('The topic could not be deleted. Please, try again.'));
}
return $this->redirect(array('action' => 'index'));
}
}
Topic.php
<?php
App::uses('AppModel', 'Model');
/**
* Topic Model
*
* @property Category $Category
* @property Comment $Comment
*/
class Topic extends AppModel {
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'title' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'body' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'category_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'modified' => array(
'datetime' => array(
'rule' => array('datetime'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Category' => array(
'className' => 'Category',
'foreignKey' => 'category_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
/**
* hasMany associations
*
* @var array
*/
public $hasMany = array(
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'topic_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}