本文整理汇总了PHP中item::set方法的典型用法代码示例。如果您正苦于以下问题:PHP item::set方法的具体用法?PHP item::set怎么用?PHP item::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类item
的用法示例。
在下文中一共展示了item::set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
function set($var, $value)
{
$value = mydb::cxn()->real_escape_string($value);
switch ($var) {
case 'serial_num':
// Test for the correct form (i.e. COH-123) 2-5 letters, hyphen, 3-7 numbers
if (preg_match('/\\b[a-zA-Z]{2,5}-[0-9]{3,7}\\b/', $value) != 1) {
throw new Exception('Rappel Equipment serial numbers must be written as 2-5 letters followed by a hyphen and 3-7 numbers (i.e. COH-1234567) : ' . $value);
} else {
// Make sure that the requested serial_num is NOT already in the database.
if ($this->is_duplicate($value, get_class($this))) {
throw new Exception('There is already a ' . get_class($this) . ' with a Serial Number of ' . strtoupper($value));
} else {
parent::set('serial_num', strtoupper($value));
}
}
break;
case 'mfr_serial_num':
//This field will store the manufacturer's serial number in the event that an item has been assigned a 'local' serial number by the owner.
//The database allows a VARCHAR of 0-15 characters
if (strlen($value) > 15) {
throw new Exception('The manufacturer\'s serial number can only be 15 characters');
} else {
$this->mfr_serial_num = $value;
}
break;
case 'use_offset':
if ($value == "") {
$this->use_offset = 0;
} elseif (!$this->var_is_int($value)) {
throw new Exception('The USE_OFFSET must be an integer value.');
} else {
$this->use_offset = $value;
}
break;
case 'in_service_date':
//This must be either blank or mm/dd/yyyy
$dates = explode("/", $value);
// The Date ($value) should be in the form: mm/dd/yyyy
if ($value != "" && !checkdate((int) $dates[0], (int) $dates[1], (int) $dates[2])) {
throw new Exception('The In-Service Date entered is not a valid date (dates must be in the form: mm/dd/yyyy)');
} else {
$this->in_service_date = $value;
}
break;
case 'retired_date':
//This must be either blank or mm/dd/yyyy
$dates = explode("/", $value);
// The Date ($value) should be in the form: mm/dd/yyyy
if ($value != "" && !checkdate((int) $dates[0], (int) $dates[1], (int) $dates[2])) {
throw new Exception('The Retirement Date entered is not a valid date (dates must be in the form: mm/dd/yyyy)');
} else {
$this->retired_date = $value;
}
break;
case 'retired_reason':
$this->retired_reason = $value;
//This value is a string with no restrictions. Just store it.
break;
case 'retired_category':
/*
if(in_array(strtolower($value),$this->valid_retired_categories)) $this->retired_category = strtolower($value);
else throw new Exception('The rappel_equipment->set() function attempted to set an invalid \'retired_category\' ('.$value.')');
*/
$this->retired_category = strtolower($value);
break;
default:
parent::set($var, $value);
// If this request is not specific to a piece of rappel equipment, let the ITEM class deal with it
//throw new Exception('The rappel_equipment->set() function attempted to modify an invalid variable ('.$var.')');
break;
}
// End: switch($var)
}