我是蛋糕的新手,完成了博客教程,现在我正在尝试一些简单的开始。但是我有一些我无法理解的东西。在模型 PersonalInformation 上,我得到了表字段的数据验证:
这是我的带有 $validate 数组的模型:
class PersonalInformation extends AppModel {
/**
* Validation rules
* @var $validate
*/
public $validate = array(
"first_name" => array(
"name" => array(
"rule" => "validName",
"message" => 'Only alpha characters and "." (dots)',
),
),
"last_name" => array(
"name" => array(
"rule" => "validName",
"message" => 'Only alpha characters and "." (dots)',
),
),
"birth_date" => array(
"date" => array(
"rule" => "date",
"message" => "Enter a valid date",
),
),
"nickname" => array(
"alphanumeric" => array(
"rule" => "alphaNumeric",
"message" => "Only alpha-numeric characters",
),
),
"gender" => array(
"notEmpty" => array(
"rule" => "notEmpty",
"message" => "Can't be empty",
),
),
);
} // end class
这是我的桌子:
CREATE TABLE `personal_informations`
(
`id` INT NOT NULL UNIQUE AUTO_INCREMENT,
`first_name` VARCHAR(45),
`last_name` VARCHAR(45),
`birth_date` DATE,
`nickname` VARCHAR(45),
`is_company` TINYINT DEFAULT 0 NOT NULL,
`picture_url` VARCHAR(255),
`gender` ENUM('m','f') NOT NULL,
`notes` TEXT,
`created` DATETIME,
`modified` DATETIME,
PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARACTER SET=utf8;
CREATE INDEX `id_idx` ON personal_informations(id);
这是视图:
<!-- /PersonalInformations/add -->
<div class="">
<h2>Create a personal information</h2>
<?php
echo $this->Form->create();
echo $this->Form->input( "PersonalInformation.first_name" );
echo $this->Form->input( "PersonalInformation.last_name" );
echo $this->Form->input(
"PersonalInformation.birth_date",
array(
"separator" => " - ",
"minYear" => date('Y') - 90,
"maxYear" => date('Y')
)
);
echo $this->Form->input( "PersonalInformation.nickname" );
echo $this->Form->input( "PersonalInformation.is_company", array( "type" => "checkbox" ));
echo $this->Form->input( "PersonalInformation.piture_url", array( "type" => "file" ));
echo $this->Form->radio( "PersonalInformation.gender", array( "m" => __("Male"), "f" => __("Female")), array( "hiddenField" => false ));
echo $this->Form->textarea( "PersonalInformation.notes" );
echo $this->Form->end( "Done" );
?>
</div>
所以问题是,由于某种原因,“昵称”是必需的,我的意思是,当我点击“昵称”为空的提交按钮时,它显示“只有字母数字字符”。对于“性别”,当没有选择任何内容时,它不会显示任何内容。
如果还有什么我需要发布的,请告诉我。