2012-07-26 27 views
1

有一個問題,我們正在創建一個採用varchar的表單,但cakephp將該字段視爲int。Cakephp表單錯過通信

那麼我們如何解決它?

這是我們的添加功能來添加關係。

public function add() { 
    $this->set('title_for_layout', 'Send A Relationship Request'); 
    $this->set('stylesheet_used', 'homestyle'); 
    $this->set('image_used', 'eBOXLogoHome.jpg'); 
    $this->layout='home_layout'; 

    if ($this->request->is('post')) { 

     $this->Relationship->set($this->request->data); 
     if ($this->Relationship->validates(array('fieldList'=>array('receiver_id','Relationship.userExists')))) 
     { 
     $username=$this->Relationship->username; 
     $this->Relationship->save($this->request->data); 
     $this->Session->setFlash('The relationship has been saved'); 
     } else { 
     $this->Session->setFlash('The relationship could not be saved. Please, try again.'); 
     } 
    } 
    } 

這裏是我們的觀點(這要求提供用戶名(VARCHAR形式))

<?php 
echo $this->Form->create('Relationship', array('action'=>'add')); 
echo $this->Form->input('sender_id',array('label'=>'Enter your username: ')); 
echo $this->Form->input('receiver_id',array('label'=>'Username of user: ')); 
echo "<br />"; 
echo $this->Form->end('Click here to add relationship'); 

?> 

回答

2

是由於你的命名約定。 SENDER_ID和receiver_id將被視爲默認整數值,因爲它代表的關係屬於發件人和關係屬於接收器,爲更好的結果,您可以更改域的命名約定,或者使用此代碼:

echo $this->Form->input('sender_id',array('label'=>'Enter your username:', 
              'type'=>'text')); 
+0

謝謝,正是我需要的。 – user1402677 2012-07-26 06:02:24