Jump to content

field auto_increment


lundy
 Share

Recommended Posts

  • 2 months later...

But how could we build unique ids with pw if needed? For example unique topic, user and task ids starting with zero and auto increment?

it would be very easy to add a hook and do this; i've seen sample code here on the forum. you would hook into the page saveReady

    public function init() {
       $this->pages->addHookAfter('saveReady', $this, 'autoIncrememt');
    }
public function autoIncrement(HookEvent $event) {
 $page = $event->arguments[0];
  if($page->template != 'someTemplate') return; 

  // some logic here to count the existing pages of this template and then add 1 and set the value of your auto increment field to that value, if it is empty.

}
Link to comment
Share on other sites

Thanks, Macrura.  :)

But it's also right... I've to think about unique (section) id vs (global) page id. Is it needed to use different IDs for different sections or simple use page id and filter with different templates/ categories.

So also thanks to you, Joss ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...