例如,
我有一个如下所示的ORM设置。
$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;
我想在传递视图之前截断 ORM 结果。我们该怎么做呢?
感谢帮助!
谢谢
这
实际上很容易,这要归功于Kohana的ORM模块中的get()
方法。你可以有一个像
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;
}
}