2013-04-15 35 views
0

我試圖保存在數據庫中有varchar(500)的description字段。當我看着螢火蟲中的Net Panel時,整個描述被張貼出來(超過200個字)。然而,在cakephp中只有75個詞正在保存。我在我的控制器中設置了一個斷點,並查看了這個請求 - >數據,它有大約150個字符。下面是我的代碼:Cakephp2.3文本區未正確發佈

<fieldset> 
<legend>Create Log</legend> 
<?php echo $this->Form->Create('Log', array('inputDefaults' => array('div' => false, 'label' => false))); ?> 
    <div class="control-group"> 
     <div class="input-prepend"> 
      <span class="add-on"><i class="icon-folder-open"></i></span> 
      <?php echo $this->Form->input('project_id'); ?> 
     </div> 
    </div> 

    <div class="control-group"> 
     <div class="input-prepend"> 
      <span class="add-on"><i class="icon-user"></i></span> 
      <input type="text" id="txtName" placeholder="Customer" /> 
      <?php echo $this->Form->Hidden('customer_id'); ?> 
      <a><span class="add-on"><i class="icon-plus" style="color: green;" onclick="window.open('<?php echo $this->Html->Url(array('controller' => 'customers', 'action' => 'add?popup')); ?>', 'Add Customer', 'height=630, width=430')"></i></span></a> 
     </div> 
    </div> 

    <div class="control-group"> 
     <div class="input-prepend"> 
      <span class="add-on"><i class="icon-time"></i></span> 
      <?php echo $this->Form->input('time_spent', array('placeholder' => 'Time spent (hrs)')); ?>    
     </div> 
    </div> 

    <div class="control-group"> 
     <div class="input-prepend"> 
      <span class="add-on"><i class="icon-book"></i></span> 
      <?php echo $this->Form->textarea('description', array('placeholder' => 'Description', 'class' => 'logTextArea', 'rows' => '7')); ?> 

     </div> 
    </div> 

<?php echo $this->Form->end(array(
    'label' => 'Save Record', 
    'class' => 'btn btn-primary', 
    'div' => false 
)); ?> 

<?php echo $this->Html->script('jquery.autocomplete', array('inline' => false)); ?> 

<?php $this->start('script'); ?> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     var options, a; 
     jQuery(function() { 
      options = { 
       serviceUrl: "<?php echo $this->Html->Url(array('controller' => 'logs', 'action' => 'autoComplete.json')); ?>", 
       minChars: 2, 
       onSelect: function(suggestion){ $('#LogCustomerId').val(suggestion.data); } 
      }; 
      a = $('#txtName').autocomplete(options); 
     }); 
    }); 
</script> 
<?php $this->end(); ?> 

控制器:

public function add() { 
    $this->set('title_for_layout', 'Add log'); 

    // Populate projects DDL 
    $this->set('projects', $this->Log->Project->find('list', array(
     'order' => array('Project.project_name') 
     ))); 

    if ($this->request->is('post')) 
    { 
     $this->Log->create(); 
     if ($this->Log->save($this->request->data)) 
     { 
      $this->Session->setFlash('Log has succesfully been created', 'default', array('class' => 'alert alert-success')); 
      $this->redirect(array('action' => 'index')); 
     } else { 
      $this->Session->setFlash('Unable to save log', 'default', array('class' => 'alert alert-error')); 
     } 
    } 
} 
+0

您的表格定義是什麼樣的?您是否嘗試清除cakephp模型緩存(app/tmp/cache/Models)?另外,將您的調試級別設置爲2並檢查執行了哪些SQL查詢以檢查是否創建了正確的查詢。 – thaJeztah

+0

嗯,對不起,只是意識到我誤解了你的問題,我是否正確理解數據已經在'$ this-> request-> data'內被截斷了?您是否嘗試調試/跟蹤原始的'$ _POST'數據? – thaJeztah

+0

@thaJeztah這是正確的,數據已經被截斷$ this-> request-> data內。我也檢查了原始的$ _POST數據,並在那裏截斷。當你說清除模型緩存時,我應該刪除模型目錄嗎? – Andrew

回答

1

此問題可能是由錯誤的PHP捨去$_POST值的某些版本引起的。

沒有重新發布信息,這個問題包含一些額外的 信息。

PHP $_POST array variables are truncated

一些(可能)相關的bug;

Bug #42824 Post Data truncated

+0

大聲笑我剛剛發現我做錯了什麼。 varchar(500)不是500個單詞,而是500個字符。我仍然不知道爲什麼它在Eclipse中被截斷,但現在一切都被正確保存了。 – Andrew

+0

恩,這是我的第一次猜測,但你提到*「...這個 - >請求 - >數據,它有大約150個字符」*,暗示它已被截斷? – thaJeztah

+0

是的,我不知道爲什麼它是這樣的。這也讓我失望了。當我設置我的調試點時,我在eclipse中檢查了$ _POST,$ _REQUEST,$ Globals和$ this,並且所有這四個地方都截斷了數據。它將在保存到數據庫後截斷更多。 – Andrew