本文整理汇总了PHP中ActiveRecord::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::isValid方法的具体用法?PHP ActiveRecord::isValid怎么用?PHP ActiveRecord::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::isValid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValid
function isValid()
{
$valid = true;
if (!$this->getData('company_id')) {
$this->errors[] = 'company_id must be set.';
$valid = false;
}
if (!$this->getData('amount_due')) {
if (!$this->getData('start_date')) {
$this->errors[] = 'start_date must be set.';
$valid = false;
}
if (!$this->getData('end_date')) {
$this->errors[] = 'end_date must be set.';
}
}
if ($valid && parent::isValid()) {
return true;
}
}
示例2: error_messages_for
/**
* Finds and retuns a HTML formatted string with errors for an ActiveRecord object
*
* Eg.
* <code>
* <?=ActiveRecordHelper::error_messages_for($person);?>
* </code>
* will show all the errors for the person object.
*
* Valid options:
* <ul>
* <li>css_class [ default formErrors ] for: <div id="" class="$css_class"></li>
* <li>heading [ default 2 1-->6 ] for: <h$heading><2 errors prohibited this form from beeing saved;/h$heading>
* <li>singular [ default error ] for: 1 $singular prohibited this...</li>
* <li>plural [ default errors ] for: 2 $plural prohibited this...</li>
* <li>oname [ default object name] for: the active record object name</li>
* </ul>
*
* @param ActiveRecord object the ActiveRecord object to check for errors
* @param array options the options where we can cusomize the look and feel of the error message.
* this includes: css_class and heading
* @return string a HTML formatted string
*/
public static function error_messages_for(ActiveRecord $record, $options = array())
{
if ($record->isValid()) {
return;
}
$css_class = isset($options['css_class']) ? $options['css_class'] : 'formErrors';
$heading = isset($options['heading']) && (int) $options['heading'] > 0 && (int) $options['heading'] < 6 ? $options['heading'] : 2;
$singular = isset($options['singular']) ? $options['singular'] : 'error';
$plural = isset($options['plural']) ? $options['plural'] : 'errors';
$oname = isset($options['oname']) ? $options['oname'] : ucfirst($record->getClassName());
$buffer = '<div id="medickFormErrors" class="' . $css_class . '">';
$part = '<ul>';
foreach ($record->getErrors() as $error) {
$part .= '<li>' . $error . '</li>';
}
$part .= '</ul>';
$st = sizeof($record->getErrors()) == 1 ? $singular : $plural;
$buffer .= '<h' . $heading . '>' . sizeof($record->getErrors()) . ' ' . $st . ' prohibited this ';
$buffer .= $oname . ' from being saved</h' . $heading . '>';
$buffer .= "\n<p>There were problems with the following fields:</p>\n";
$buffer .= $part;
return $buffer . '</div>';
}
示例3: isValid
function isValid()
{
$valid = true;
if (!Util::is_a_date($this->get('start_date'))) {
$this->errors[] = 'Contract ' . $this->id . ' has no start date.';
$valid = false;
}
if ($valid && parent::isValid()) {
return true;
}
}