Database Cakephp表单未完成通信

Database Cakephp表单未完成通信,database,forms,cakephp,varchar,Database,Forms,Cakephp,Varchar,有一个问题,我们正在创建一个采用varchar的表单,但是cakephp将该字段视为int 那么我们该怎么解决呢 下面是添加关系的add函数 public function add() { $this->set('title_for_layout', 'Send A Relationship Request'); $this->set('stylesheet_used', 'homestyle'); $this->set('image_used', 'e

有一个问题,我们正在创建一个采用varchar的表单,但是cakephp将该字段视为int

那么我们该怎么解决呢

下面是添加关系的add函数

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))的表单)


这是由于您的命名约定。默认情况下,发送方和接收方id将被视为整数值,因为它表示关系属于发送方,关系属于接收方。为了获得更好的结果,您可以更改字段的命名约定或使用以下代码:

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