* @param array $names list of attributes to be set null. If this parameter is not given,
* all attributes as specified by {@link attributeNames} will have their values unset.
* @since 1.1.3
*/
publicfunctionunsetAttributes($names=null)
{
if($names===null)
$names=$this->attributeNames();
foreach($namesas$name)
$this->$name=null;
}
/**
* This method is invoked when an unsafe attribute is being massively assigned.
* The default implementation will log a warning message if YII_DEBUG is on.
* It does nothing otherwise.
* @param string $name the unsafe attribute name
* @param mixed $value the attribute value
* @since 1.1.1
*/
publicfunctiononUnsafeAttribute($name,$value)
{
if(YII_DEBUG)
Yii::log(Yii::t('yii','Failed to set unsafe attribute "{attribute}" of "{class}".',array('{attribute}'=>$name,'{class}'=>get_class($this))),CLogger::LEVEL_WARNING);
}
/**
* Returns the scenario that this model is used in.
*
* Scenario affects how validation is performed and which attributes can
* be massively assigned.
*
* A validation rule will be performed when calling {@link validate()}
* if its 'on' option is not set or contains the current scenario value.
*
* And an attribute can be massively assigned if it is associated with
* a validation rule for the current scenario. Note that an exception is
* the {@link CUnsafeValidator unsafe} validator which marks the associated
* attributes as unsafe and not allowed to be massively assigned.
*
* @return string the scenario that this model is in.
* @since 1.0.4
*/
publicfunctiongetScenario()
{
return$this->_scenario;
}
/**
* Sets the scenario for the model.
* @param string $value the scenario that this model is in.
* @see getScenario
* @since 1.0.4
*/
publicfunctionsetScenario($value)
{
$this->_scenario=$value;
}
/**
* Returns the attribute names that are safe to be massively assigned.
* A safe attribute is one that is associated with a validation rule in the current {@link scenario}.
* @return array safe attribute names
* @since 1.0.2
*/
publicfunctiongetSafeAttributeNames()
{
$attributes=array();
$unsafe=array();
foreach($this->getValidators()as$validator)
{
if(!$validator->safe)
{
foreach($validator->attributesas$name)
$unsafe[]=$name;
}
else
{
foreach($validator->attributesas$name)
$attributes[$name]=true;
}
}
foreach($unsafeas$name)
unset($attributes[$name]);
returnarray_keys($attributes);
}
/**
* Returns an iterator for traversing the attributes in the model.
* This method is required by the interface IteratorAggregate.
* @return CMapIterator an iterator for traversing the items in the list.
*/
publicfunctiongetIterator()
{
$attributes=$this->getAttributes();
returnnewCMapIterator($attributes);
}
/**
* Returns whether there is an element at the specified offset.
* This method is required by the interface ArrayAccess.
* @param mixed $offset the offset to check on
* @return boolean
* @since 1.0.2
*/
publicfunctionoffsetExists($offset)
{
returnproperty_exists($this,$offset);
}
/**
* Returns the element at the specified offset.
* This method is required by the interface ArrayAccess.
* @param integer $offset the offset to retrieve element.
* @return mixed the element at the offset, null if no element is found at the offset
* @since 1.0.2
*/
publicfunctionoffsetGet($offset)
{
return$this->$offset;
}
/**
* Sets the element at the specified offset.
* This method is required by the interface ArrayAccess.
* @param integer $offset the offset to set element
* @param mixed $item the element value
* @since 1.0.2
*/
publicfunctionoffsetSet($offset,$item)
{
$this->$offset=$item;
}
/**
* Unsets the element at the specified offset.
* This method is required by the interface ArrayAccess.
* @param mixed $offset the offset to unset element