2012-10-29 141 views
0

我目前正在嘗試從YouTube插入信息到數據庫中以備將來使用。當插入進行時,我不會遇到任何錯誤,並且Flash會像數據插入成功一樣返回。問題是隻有一列數據被插入到表中。這是我正在使用的代碼。數據沒有插入CakePHP

的觀點:

<?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-> input(type => 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

愚蠢在這一個上得到了我最好的...語法錯別字是什麼阻止我能夠保存在這裏的數據:if($this->Youtube->save($this->request-data))這應該是if($this->Youtube->save($this->request->data))。錯過了一個> ......我想這個問題的一半時間是手,儘管... dang拼寫錯誤!

+0

由於變量名不能包含破折號,因此應該在應用正確語法突出顯示的任何編輯器上記下此錯字:) – user221931