【发布时间】:2013-08-07 13:45:10
【问题描述】:
我有一个表格,其中的值不在我的数据库中。我不想对它们进行验证,所以我使用字段名称制定了一些验证规则。不知何故,验证规则没有被使用。
我已经尝试过设置不同的规则。文件名正确,因为 $hasMany 连接有效。
希望你能帮上忙!
表格:
<?php
echo $this->Form->create('Map');
echo $this->Form->input('min_x');
echo $this->Form->input('max_x');
echo $this->Form->input('min_y');
echo $this->Form->input('max_y');
echo $this->Form->end('Submit');
?>
验证规则:
public $validate = array(
'min_x' => array(
'rule' => 'Numeric',
'message' => 'Please enter a numeric value.'
),
'max_x' => array(
'rule' => 'Numeric',
'message' => 'Please enter a numeric value.'
),
'min_y' => array(
'rule' => 'Numeric',
'message' => 'Please enter a numeric value.'
),
'max_y' => array(
'rule' => 'Numeric',
'message' => 'Please enter a numeric value.'
),
);
【问题讨论】:
-
$validate在什么类和文件名? -
@ಠ_ಠ 好问题,应该在
Map模型中。 -
如前所述,它位于正确的文件中。它在模型文件夹的 Map.php 文件中。类是:class Map extends AppModel
-
其实,没关系:规则是否区分大小写?
'rule' => 'Numeric'到'rule' => 'numeric' -
它们区分大小写。
标签: php validation cakephp