How do I achieve virtual attributes in CakePHP (using code, not SQL) as implemented in Ruby on Rails
Posted
by
ash
on Stack Overflow
See other posts from Stack Overflow
or by ash
Published on 2010-12-29T03:26:45Z
Indexed on
2010/12/29
4:53 UTC
Read the original article
Hit count: 170
ruby-on-rails
|cakephp
Source: http://asciicasts.com/episodes/16-virtual-attributes
I'd like to achieve a similar setup as below, but in CakePHP and where the virtual attributes are created using code, not SQL (as documented at http://book.cakephp.org/view/1070/Additional-Methods-and-Properties#Using-virtualFields-1590).
class User < ActiveRecord::Base
# Getter
def full_name
[first_name, last_name].join(' ')
end
# Setter
def full_name=(name)
split = name.split(' ', 2)
self.first_name = split.first
self.last_name = split.last
end
end
© Stack Overflow or respective owner