Hello all again,
I was following this tutorial, www.aidanf.net/rails_user_authentication_tutorial and he utilizes a ruby native property of attr_accessor (which sets getters and setters). But what is interesting is how the model treats them as almost normal properties, setting them as it goes through mass-assignments and validation is aware of the properties. The only difference seems that the model doesn't save them to the database.
Is there a way to do this kind of functionality in akelos?
Akelos attributes can be set/get using these approaches (we don't have attr_accessor in PHP :( )
$User->get('password');
$User->set('password', 'mypass');
that will get/set a single attribute.
If you want to mass assign/retrieve attributes you can use
$attributes = $User->getAttributes();
$User->setAttributes($attributes);
If you need to do real work on setters/getters you can define in your config/config.php file
define('AK_ACTIVE_RECORD_ENABLE_AUTOMATIC_SETTERS_AND_GETTERS', true);
this is not enabled by default as it might cause recursion problems if you're not aware of it. When you add this setting calling
$User->get('password');
will look for a method like
$User->getPassword();
if it exists and will return the value provided by the specific getter. The same goes for setters
$User->set('password', 'mypass');
will look for a method like
$User->setPassword('mypass');
That is the way mass assignment getters and setters work in Akelos.
Hope you find it helpful.
Hi,
I'm reviving an old thread here, but I tried this and, in fact, it works when you use: <pre> $User->get('password'); </pre>
but it doesn't seem to work with the Sintags markup. If I do the following within my view: <pre> {user.password} </pre>
Nothing gets displayed...
Any idea ?
Thank you very much.
Try
{user.password}
and not
{User.password}
as it is case sensitive.
Thank you bermi but I don't think that's it. The user.password was an example to explain the concept, but the code I have here uses the right variable names... And again, when I call it through a PHP call (not using sintags), it works, but when using sintags it doesn't... Also, I'm using the 0.9 version of Akelos, this might be it...
I'll investigate further when I get time and let you know.
Thank you once again.
Hi Bermi,
I do confirm with Akelos 1.0.1:
this syntax works: <?= $User->get('password') ?>
this syntax does NOT work: <?= $User->password ?>
this syntax does NOT work either: {User.password}
Small bug, I know, but still a bug in my opinion :-)
1 to 7 of 7