What is the difference between $this->foo and $this->Foo?
No difference at all they both point to the same object.
if you want to call a parent method, you can do it like
parent::init();
How does init() get called when a new instance of the model is created by the controller? Akelos tries to infer the instance variables from the database schema. But what if I want to add and initialize additional instance variables?
So as a simple example, say I have a model class called Foo. It has a private instance variable called $timeOfBirth that gets set by a call to the function time() when the models gets instantiated by the controller. It also has a public instance variable $timeAlive that gets set by a call to a public function timeSinceBirth that simply subtracts the $timeOfBirth from a new call to time(). I would like it so that every time I made a call to the template show.tpl, it would simply display something like <h1>I've been alive for {Foo.timeAlive}</h1>. How would I do this in Akelos?
Use the default created_at attribute which is set automatically for you when storing an Active Record object.
This would be the simple way.
On your view:
<h1>I've been alive since <%= distance_of_time_in_words_to_now Foo.created_at %></h1>
A more complicated way that shows the basis of constructor overloading as you asked for would be
on your model:
private $_time_alive;
function __construct()
{
$attributes = (array)func_get_args();
parent::init($attributes);
$this->time_alive = $this->timeSinceBirth();
}
private timeSinceBirth()
{
return $this->isNewRecord() ? 0 : time() - Ak::getTimestamp($this->get('created_at'));
}
on your view:
<h1>I've been alive for {Foo.time_alive}</h1>
Hope you find it useful.
Barry,
Normally PHP uses share-nothing approach, and that is what makes PHP application deployment and scaling so easy. The simplest way to persist models is using the database. You might persist objects and rendered views in memory using memcached or use an application server like mongrel in PHP.
Using appserver server is the path I'm working on to allow persistance, but it stills on its infancy.
1 to 4 of 4