After inserting a new article we redirect to the individual article page using this cold here.
We're doing exactly the same thing here.
When we update an existing article as we know repeating ourselves in code isn't a good idea.
So let's extract this out into a function let's create a new file in the includes folder and Kallet
u r l e p h.
P.
Let's create a new function called redirect that takes an argument of the path we're redirecting to.
Let's copy the code were using to redirect.
And paste this inside out a new function.
Let's take the hard coded path out of here and replace it with the value of the argument.
Finally let's add a p-h pickup comment block to describe the function.
It's argument and its return value.
If a function doesn't return anything like this one then we put void as its return value in the comment.
Now in the new article script we can require this new file.
Then we can replace this redirect code here with a call to the new function.
Passing in the path of the file we want to redirect to including the query string containing the idae.
Let's do the same in the edit article script first requiring the new file.
Here at the top and then replacing the redirect code.
With a call to the new function like that.
Let's give that a try.
If I enter some data and submit the farm to create a new article will it be directed as before.
If we edit this article and change it field when we submit the farm will also redirected as expected
redirecting to another u r l is something that we need to do quite often when working with the database
so it's useful to have a generic function we can call to do that.