user3580230
user3580230

Reputation: 1

No change of slug when editing record with slugable behaviour

Cakephp:

public function edit($id)
        {
            if (!$id) 
            {
                throw new NotFoundException(__('Invalid ' . $this->modelClass));
            }

            $record = $this->{$this->modelClass}->findById($id);
            if (!$record) 
            {
                throw new NotFoundException(__('Invalid ' . $this->modelClass));
            }

            if ($this->request->is('post') || $this->request->is('put')) 
            {
                $this->{$this->modelClass}->id = $id;
                if ($this->{$this->modelClass}->save($this->request->data)) 
                {
                    $this->Session->setFlash($this->modelClass . ' has been updated.');
                    $this->redirect(array('action' => 'index'));
                } else {
                            $this->Session->setFlash('Unable to update your ' . $this->modelClass . '.');
                       }
        }

        if (!$this->request->data) 
        {
            $this->request->data = $record;
        }       
    };

I am trying to update the record in custom cms which built in cakephp framework with use slugable behaviour for link with record. but when we edit a record and change the name of page then the slug also changed. but i don't want to change the slug when update the name of record.

Thank you for any assistance with this.

Upvotes: 0

Views: 58

Answers (2)

the1dv
the1dv

Reputation: 931

Why not just remove the slug either from the form you are editing or by unsetting it in the edit?

unset($this->request->data[$this->modelClass]['slug']);

Or if your problem is the other way around ensure that you are submitting the slug properly

Upvotes: 1

user3594034
user3594034

Reputation:

By default, we get no change of slug when editing record.

What about $actsAs settings of the Model ?

If 'update' is true, set it to false or remove it.

Upvotes: 0

Related Questions