Skip to content

Instantly share code, notes, and snippets.

@novalagung
Last active December 12, 2015 06:09
Show Gist options
  • Save novalagung/4727109 to your computer and use it in GitHub Desktop.
Save novalagung/4727109 to your computer and use it in GitHub Desktop.
<?php
defined('SYSPATH') or die('No direct script access.');
class Model_Child extends Model_Parent {
}
<?php
defined('SYSPATH') or die('No direct script access.');
class Model_Parent extends ORM {
public function __construct() {
parent::__construct();
}
public function next_id($model = '') {
if ($model == '') {
$model = new ReflectionClass(get_class($this));
$model = str_replace('Model_', '', $model->name);
}
$o = ORM::factory($model)->limit(0)->offset(0)->order_by($this->_primary_key, 'desc')->find();
return $o->get($this->_primary_key) + 1;
}
}
<?= ORM::factory('child')->next_id() ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment