You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added this to my copy of sluggable. It's a single use thing, so maybe you don't want to bloat your code with it, but here it is in case you think it would be useful for others:
/**
* fixes slugs on all current objects (useful when working with existing data set).
* @param AppModel $model the model that this behavior is applied to
*/
public function fix_slugs (&$model) {
//no need for extra junk
$model->virtualFields = array();
$model->contain = array();
//fetch all data for current model
$data = $model->find('all');
//force overwriting of slugs, even if not set up for this model as such
$this->settings[$model->alias]['overwrite'] = true;
//save all data for model - slugs should be generated automatically
$model->saveAll($data);
}
It does have to be invoked somewhere for each model. I suppose it could be done in app_model, but I just went into the controller that needed slugs and added:
function fix_slugs () { $this->YOURMODELNAME->fix_slugs(); }
I added this to my copy of sluggable. It's a single use thing, so maybe you don't want to bloat your code with it, but here it is in case you think it would be useful for others:
It does have to be invoked somewhere for each model. I suppose it could be done in app_model, but I just went into the controller that needed slugs and added:
Then I went to http://localhost/YOURMODELNAME/fix_slugs and it slugged everything. I then commented out the method so it could never be called via URL GET.
The text was updated successfully, but these errors were encountered: