我目前正在尝试将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; ?>
我认为可能有一种更好的方式来显示项目并设置值,虽然我是新蛋糕所以我不确定我应该寻找什么,以便制作一个预设不变的值其他形式的表单而不是form-&gt; input(type =&gt; hidden);
控制器:
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错误。任何帮助将不胜感激。
答案 0 :(得分:0)
愚蠢在这一方面得到了最好的...语法拼写错误导致我无法在此处保存数据:if($this->Youtube->save($this->request-data))
应该是if($this->Youtube->save($this->request->data))
。错过了一个>
......我想有一半的时间就是问题,但这是一个错误的错误!