0

我正在使用 Propel 和 PFBC(来自 Builder 类的 php)。我使用propel php orm(数据库)在xml文件中编写了验证,现在我想在单击登录按钮时使用它们。这意味着我想检查表单变量和数据库验证规则的验证。我的 xml 代码看起来像这样

<table name="names" phpName="Name">
<column name="nameid" phpName="Nid" type="integer" size="11" required="true" primaryKey="true"
autoIncrement="true" description="Name ID"/>
<column name="name" phpName="Name" type="varchar" size="50" required="true"
description="Name"/>
<validator column="name">
<rule name="required" message="Name is Required"/>
<rule name="minLength" value="3" message="Enter Valid Full-Name, Minimum of 3 characters"/>
<rule name="maxLength" value="20" message="Invalid Entry"/>
<rule name="match" value="/^[\w]+$/" message="No Special Character Allowed"/>
<rule name="unique" />
</validator>
</table>

<table name="relations" phpName="Relations">
<column name="rid" type="integer" size="11" required="true" primaryKey="true" autoIncrement="true"
description="Relational ID"/>

<column name="pnid" type="integer" size="11" required="true" description="name User ID"/>

<column name="rnid" type="integer" size="11" required="true" description="name Relationship ID"/>

<column name="relation" type="varchar" size="100" required="true" description="Relationship"/>

<validator column="relation">
<rule name="required" message="Relationship Type is Required" />
<rule name="match" value="/^([\w])+([\.\w\-]+)+$/" message="Enter a Valid String" />
<rule name="minLength" value="3" message="Enter a Valid Relation Ship"/>
<rule name="maxLength" value="20" message="Invalid Entry"/>
</validator>

<foreign-key foreignTable="names" onUpdate="CASCADE" onDelete="CASCADE">
<reference local="pnid" foreign="nid" />
<reference local="rnid" foreign="nid" />
</foreign-key>
</table>
4

1 回答 1

0

我猜你只是想知道如何运行 Propel 的验证?如果是这样,您可以这样做:

$name = new Name();
$name->setName($_POST['Name']); // or however you want to do it
// set other object properties

if (!$name->validate()) {
  $errors = $name->getValidationFailures();
  foreach ($errors as $field => $error) {
    // do something with the valiadtion errors
  }
}
于 2013-01-28T17:30:23.557 回答