我目前正在尝试将来自 YouTube 的信息插入数据库以供将来使用。当插入完成并且闪存返回时,我没有收到任何错误,就好像数据已成功插入一样。问题是只有一列数据被插入到表中。这是我正在使用的代码。
风景:
<?php foreach ($videos->data->items as $video) : ?>
<?php echo $this->Form->create('Youtube', array('action' => 'addNews')); ?>
<tr>
<td><?php echo $this->Html->image($video->thumbnail->hqDefault, array('width' => 72, 'height' => 56, 'alt' => 'image')); ?></td>
<td><?php echo $this->Time->niceShort($video->uploaded); ?></td>
<td><?php echo $video->category; ?></td>
<td><?php echo $video->title; ?></td>
<td><?php echo $this->Text->truncate($video->description, 50); ?></td>
<td><?php echo $this->Number->precision($video->rating, 2); ?></td>
<?php echo $this->Form->input('youtube_url', array('type' => 'hidden', 'value' => $video->id)); ?>
<?php echo $this->Form->input('uploaded', array('type' => 'hidden', 'value' => $this->Time->format('Y-m-d H:i:s', $video->uploaded))); ?>
<?php echo $this->Form->input('updated', array('type' => 'hidden', 'value' => $this->Time->format('Y-m-d H:i:s', $video->updated))); ?>
<?php echo $this->Form->input('uploader', array('type' => 'hidden', 'value' => $video->uploader)); ?>
<?php echo $this->Form->input('category', array('type' => 'hidden', 'value' => $video->category)); ?>
<?php echo $this->Form->input('title', array('type' => 'hidden', 'value' => $video->title)); ?>
<?php echo $this->Form->input('description', array('type' => 'hidden', 'value' => $video->description)); ?>
<?php echo $this->Form->input('sqDefault', array('type' => 'hidden', 'value' => $video->thumbnail->sqDefault)); ?>
<?php echo $this->Form->input('hqDefault', array('type' => 'hidden', 'value' => $video->thumbnail->hqDefault)); ?>
<?php echo $this->Form->input('default_player', array('type' => 'hidden', 'value' => $video->player->default)); ?>
<?php echo $this->Form->input('mobile_player', array('type' => 'hidden', 'value' => $video->player->mobile)); ?>
<?php echo $this->Form->input('duration', array('type' => 'hidden', 'value' => $video->duration)); ?>
<?php echo $this->Form->input('rating', array('type' => 'hidden', 'value' => $video->rating)); ?>
<?php echo $this->Form->input('like_count', array('type' => 'hidden', 'value' => $video->likeCount)); ?>
<?php echo $this->Form->input('view_count', array('type' => 'hidden', 'value' => $video->viewCount)); ?>
<?php echo $this->Form->input('comment_count', array('type' => 'hidden', 'value' => $video->commentCount)); ?>
<?php echo $this->Form->input('embed', array('type' => 'hidden', 'value' => $video->accessControl->embed)); ?>
<td><?php echo $video->viewCount; ?></td>
<td><?php echo $video->accessControl->embed; ?></td>
<td><?php echo $this->Form->submit('Add News'); ?></td>
</tr>
<?php //echo $this->Form->end(); ?>
<?php endforeach; ?>
我想也许有更好的方法来显示项目并设置值,尽管我是蛋糕新手,所以我不确定我应该寻找什么来制作一个具有除表单之外的预设不可更改值的表单- >输入(类型=>隐藏);
控制器:
if($this->request->is('post') || $this->request->is('put')) {
//debug($this->request->data);
if($this->Youtube->save($this->request-data)) {
$this->Session->setFlash('Your post was added');
$this->redirect($this->referer());
}
}
我检查了我对表格等的命名,它们都是正确的。我不确定中断发生在哪里,或者我如何才能得到蛋糕来传递正在发生的任何 MySQL 错误。任何帮助将非常感激。