Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorThijs
     

    Is it possible in Akelos to set something like this in a model (example from api.rubyonrails.com):

    class User < ActiveRecord::Base
       def full_name
         "#{first_name}. #{last_name}"
       end
    end
    

    So I could use:

    $User->collect($User->findBy('role_id',2),'full_name','id')
    

    .. in a view to make a selection menu with the full names of people?

    • CommentAuthorKaste
     

    this would be

    class User...
    function getFullName()
    {
        return $this->firstname . $this->lastename;
    }
    
    • CommentAuthorThijs
     

    ah, okay.

    Didn't know I should use get + camelcased name, because I tried:

    function full_name()
    {
       return $this->first_name.' '.$this->last_name;
    }
    

    .. but that didn't work.

    Thanks!

    • CommentAuthorThijs
     

    aha, so that's what virtual or transparent attributes are, being discussed in this post. (learning new tricks every day)

    I’ve got another one: I want to make a collection of a model that does not have a name column, the names are defined by a belongs_to association to another column (energysourcename) which has localized name columns.

    So I could do this:

    function getName()
    {
       $this->energysourcename->load();
       return $this->energysourcename->{$_SESSION['lang'].'_name'};
    }
    

    But maybe there's a nicer, shorthand way of doing it without using $_SESSION['lang'] ?

    • CommentAuthorKaste
     

    .

    ->getCurrentLocale()
    
    • CommentAuthorsalavert
     

    Or try with

    class Person extends ActiveRecord
    {
        var $combined_attributes = array(array('name', "%s %s", 'first_name', 'last_name'));
    }
    

    Now you can user Person->get('name')