Cakephp形成错过沟通

时间:2012-07-26 05:36:33

标签: database forms cakephp varchar

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

那我们该如何解决呢?

这是我们添加关系的添加功能。

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');

?>

1 个答案:

答案 0 :(得分:2)

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

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