milesj / utility

[Deprecated] A CakePHP plugin for common utility classes.
MIT License
69 stars 24 forks source link

Sluggable dynamic scope #8

Closed idev247 closed 11 years ago

idev247 commented 11 years ago

I'm not sure how to approach this... How can I make the Sluggable's _makeUnique scope dynamic? I only know the scope once the beforeSave is called but the scope is set in the settings. Example of my scope:

$scope = array('StoreCollection.store_id' => $this->storeId);

Maybe I could change it so that when beforeSlug is called it also passes $this.The call would be like this:

$slug = $model->beforeSlug($this, $slug);

The model would have this:

public function beforeSlug($behavior, $slug) {
    $behavior->settings[$this->alias]['scope'] = array('StoreCollection.store_id' => $this->storeId);
    return $slug;
}

Would that work? Is there a better way? (sorry for the edits... github submitted the form when I hit return/enter)

idev247 commented 11 years ago

I think the beforeSlug was modified? Thanks! I wasn't sure if it was a good practice to pass $this in a function. I'll try it!

milesj commented 11 years ago

Yeah its in master right now, haven't tagged yet. Let me know if that works for you.