Please refer to here
Simply put:
$Person->get("name");
$Person->set("name", value);
which will call getName and setName in the Model.
You can simply declare the virtual attributes in the class and declaring the variable in the init() method should also work just fine. Other ActiveRecord methods work just fine with them if that's what you mean by ActiveRecordHelpers.
class User extends ActiveRecord
{
var $password = null;
function setPassword($value) { /* ... */ }
function validate() {
$this->validatesLengthOf('password', array('minimum'=>5));
}
}
I should also mention that I used the automatic getters and setters configuration since my web app didn't have many relational models. I doubt if that really affects how akelos accesses the attributes (besides using the mass assign/retrieval methods).
Also, since it isn't an actual database field. using the view's input helper wouldn't work properly like other database fields:
<!-- does not work. returns nothing -->
<%= input 'user', 'password' %>
Instead, you'll have to specify the exact kind of input field:
<!-- generates a password input field -->
<%= password_field 'user', 'password' %>
As a side note, Bermi has implemented a User model in his project that avoided this issue entirely by using the beforeCreate() and beforeUpdate() methods that encrypt the password before it is saved to the database.
Hopefully I addressed your question. :)
Did you add the define statement into your config.php file?
define('AK_ACTIVE_RECORD_ENABLE_AUTOMATIC_SETTERS_AND_GETTERS', true);
This will make the enable the custom attributes to be set by getters and setters.
setAttribute(...)
will call setYourSetter(...)
So
function setPassword($value)
{
$this->password = $value;
}
function getPassword()
{
return $this->password;
}
should do the trick. Now you can do $this->set('password',$value)
look here for a different example.
yes.
$attributes = array(
'user_name' => 'bhembree',
'password' => 'tries hard on virtual attributes'
);
//then all of the following should work:
$User =& new Model($attributes);
$this->create($attributes); //uses setAttributes internally
//therefore:
$this->setAttributes($attributes);
can you write a test?
I'm still not quite sure why getAttributes() doesn't work. It must have to do with the call getAvailableAttributes() in the getAttributes() method.
+1,
and: I don't know if this is an issue we should solve.
1 to 13 of 13