This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

jfo
jfo

Hi,

On my plugin create page I have the redirect URL defined to a field which name is not id. So I read the docs and I just changed

redirect: acme/blog/posts/update/:id

to

redirect: acme/blog/posts/update/:myOtherField

My model $primaryKey is also set to use myOtherField.

However, when a record is saved it's redirecting to acme/blog/posts/update/0- always passing the 0 zero value.

If I navigated directly to acme/blog/posts/update/123 the update form correctly loads the data associated with the record 123, so I assume there is nothing wrong with the update view or with the controller.

Any ideas why myOtherField value is not being passed to the redirect URL?

Vijay Wilson
Vijay Wilson

I think you have to include redirect parameter under update section in config_form.yaml

redirect: acme/blog/posts/create

Last updated

jfo
jfo

Hi @Vijay, thanks for your comment! Unfortunately still not working. I ended up creating the id field on my database table, even so it's still not working.

Here is the content of my controller's config_form.yaml file:

name: Posts
modelClass: acme\blog\\Models\Post
form: $/acme/blog/models/post/fields.yaml
defaultRedirect: acme/blog/posts
create:
    title: 'New post'
    redirect: 'acme/blog/posts/update/:id'
    redirectClose: acme/blog/posts
update:
    title: 'acme.blog::lang.post.preview.title'
    redirect: 'acme/blog/posts/update/:id'
    redirectClose: acme/blog/posts
preview:
    title: 'acme.blog::lang.post.preview.title'

What's wrong here? Why after creating a new record OctoberCMS keeps redirecting users to acme/blog/posts/update/0 ?

Last updated

Ran
Ran

I have the same problem as you.

Is there any way to replace the id to slug?

Last updated

sam12922
sam12922

Wow! I've been struggling with this exact same issue all day. I've the issue as far as October\Rain\Router\Helper.php line 94 in the function parseValues($object, $columns, $string).

Everything looks to be working correctly, and if I hard code the correct field by changing $object->{$column} to $object->myOtherField (to use OP's terms), it still returns 0.

However, if you replace myOtherField with a non-key field (either in Helper.php or in the config_form.yaml redirect setting), it will return a proper value. So the problem with returning zero is limited to the primary key.

Last updated

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.