Norks
Norks

Reputation: 410

kohana - truncating db results ORM before passing to view

For example,

I have an ORM set up like below.

$test = new Model_Test();
$test_result = $test->find_all();

foreach ($test_result as $tmp) :

    // i would like to truncate the the $tmp->name and put it back to $test ORM like

    $test->name = truncate($tmp->name, 20); 

endforeach;

I would like to truncate the ORM result before passing to view. How can we do that?

Help appreciated!

thanks,

Upvotes: 0

Views: 173

Answers (1)

kero
kero

Reputation: 10638

This is actually quite easy thanks to the get() method in Kohana's ORM module. You can have a script as simple as

class Model_Test extends ORM
{
    protected $_stringLength = 20;

    public function get($column)
    {
        $value = parent::get($column);

        if (is_string($value))
            return substr($value, 0, $this->_stringLength);
        else
            return $value;
    }
}

Upvotes: 1

Related Questions