有一个问题,我们正在创建一个采用 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');
?>