Version 3, last updated by fonny at 23 Mar 19:16 UTC

This is the 'plain' way of writing code:

$controller = KService::get('com://admin/grocer.controller.fruits');
$model = $controller->getModel();
$model->set('name', 'Apple');
$model->set('search', 'apple');
$model->set('limit', 5);
$list = $model->getList();

However, when a method returns an object, you can use that object right away without storing it in a variable first. Also, in the model and other classes there is a 'magic setter' method that allows you to treat the state variables as class variables, so set('limit', 5) becomes ->limit(5). In our example, each method call returns an object, so we can chain the methods:

$list = KService::get('com://admin/grocer.controller.fruits') // returns a controller object
    ->getModel() // returns a model object
    ->name('apple') // returns a model object
    ->search('Apple') // returns the same model object
    ->limit(5) // ... and again
    ->getList() //finally returns the list as a rowset object

The convention in Nooku is that setters and actions (almost) always return the object itself ($this);

For example:

$row = $table->select(null, KDatabase::FETCH_ROW); // returns an new row with the table's defaults
$foo = $row->save(); // save() returns the row itself
var_dump($row === $foo); // TRUE, $row and $foo are both references to the same object