I've an AR that i also want to use as form model. Therefore i added some custom attributes:
<?php
class Zeit extends CActiveRecord
{
public customerID;
public safeAttributes()
{
return array('customerID', ...); // list of all db columns
}
}
I need this customerID as i have a dropdown with customers that are not directly related to this AR. The dropdown value should be kept e.g. on unsuccessful validation. This works. But i also want to store the AR in session when saving, and restore the attributes from this session object, to pre-fill form values on return to the page.
If i use getAttributes(true), customerID is missing from the list of attributes. Am i missing something?
So safeAttributes() only defines the attributes that can be set, but they will not be included in getAttributes()? I think i misunderstand the API for the parameter for getAttributes then:
Quote
If this is true (default), then all attribute values will be returned, including those that are not loaded from DB (null will be returned for these attributes).
What are those attributes "not loaded from DB"? And what values should i use to loop?
safeAttributes is only used by setAttributes. It has nothing to do with getAttributes.
A column may or may not be loaded into AR, depending on the SELECT option of query criteria (by default, every column is loaded). When an AR is new (to be inserted), only those attributes whose values are set are considered as loaded.
So when the parameter is true, it means the return value will contain every column.