Jump to content

Recommended Posts

Posted

I need the equivalent of a auto_increment mysql field for user_id's.  In mysql, it's a setting of the field.  How do I accomplish this with processwire.

Thanks, Aloha

  • 2 months later...
Posted

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?

Posted

How are you planing to use ids?

Since everything is a page, everything gets a unique ID. Though not starting from zero for each item. But that is not needed in PW for controlling data.

  • Like 1
Posted

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.

}
Posted

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 ;)

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
×
×
  • Create New...