Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthorJeff
    • CommentTimeSep 15th 2007
     

    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?

    •  
      CommentAuthorbermi
    • CommentTimeSep 16th 2007
     

    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.

    • CommentAuthorJeff
    • CommentTimeSep 17th 2007
     
    thanks Bermi! It works perfectly as needed :)
Add your comments
    Username Password
  • Format comments as