Jezek Jezek Mon Jan 17 01:07:42 -0500 2011

Subject: Simple getter

Hello I am trying to add a "getter" using this code:

function get_status_pretty() {
return 'test';
}

I would like to be able to do echo $company->status_pretty;

I added it to the company model of course.

Yet echo $company->status_pretty; says undefined property.


Kien La Mon Jan 17 21:21:16 -0500 2011

Are you using the nightly build?

Jezek Jezek Mon Jan 17 22:51:42 -0500 2011

I got the one from January 17th, latest one.

Jacques Fuentes Sat Feb 05 17:06:05 -0500 2011

Is status_pretty a field on your table? Getters work by declaring a function function get_name() where `name` is a field on your table.

Jezek Jezek Sat Feb 05 19:21:01 -0500 2011

It isn't a real field, it is just a virtual field.

Jacques Fuentes Sun Feb 06 11:21:58 -0500 2011

Is it an aliased attribute like here?

Jezek Jezek Sun Feb 06 14:13:06 -0500 2011

What I want to do is when I do $company->status_pretty or what not, it takes the value of the column "status", which is a number, and finds the corresponding name for that number. So it's not an exact alias.

Jacques Fuentes Sun Feb 06 16:49:19 -0500 2011

I see no reason why this wouldn't work. You may want to double check that you are definitely using the latest build of our framework and not the stable download. Please also provide me the full code example so I can solve your issue. Thanks.

Krzysiek Krajewski Sat Jan 28 11:04:54 -0500 2012

I've encountered the same problem. The reason is really simple - bug in documentation:
http://www.phpactiverecord.org/docs/ActiveRecord/Model#method__get
There should be:
class User extends ActiveRecord\Model {
static $getters = array('name');      <----- missing line !!!!!!!

In setters you should also add:
http://www.phpactiverecord.org/projects/main/wiki/Utilities#attribute-setters
static $setters = array('name');

I found it in Model.php ;]

Yoan B Sat Jan 28 11:13:49 -0500 2012

@Krzysiek where in Model.php?

This ons is the one: https://github.com/kla/php-activerecord/blob/master/lib/Model.php

Krzysiek Krajewski Sat Jan 28 11:16:51 -0500 2012

Ok - i have old version od AR :(

I can see now it was changed:
elseif (method_exists($this,"set_$name")) {
$name = "set_$name";
return $this->$name($value);
}

Documentation is correct with actual version and I need update ;]

(1-10/10)