1 to 6 of 6
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?
this would be
class User...
function getFullName()
{
return $this->firstname . $this->lastename;
}
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!
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'] ?
.
->getCurrentLocale()
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')
1 to 6 of 6