The only page we have left to convert to pdl is the new article page.
If I open the page without changing anything we see the farm but each field contains an error saying
the article variable doesn't exist.
That's because here in the form which we share with the edit page we're now using an article object's
properties instead of simple variables.
So in our new article script let's remove these variables and create a new article object instead to
create a new article we need the article class so that's require It's up here.
Replacing the article.
Include which we no longer need.
While we're here let's replace the database include with the class as well.
And in the browser the errors have gone and the empty farm works again.
Next if the form is submitted were getting the values from the farm and then inserting in you rijkaard
were doing something similar in the edit script only using an object method instead.
So start by copying this.
And replacing this code.
Like that.
Then instead of calling the update method.
Let's change this to a method which is right in a moment.
Let's call it create and then in our article class we can add this new method.
We're going to be doing something similar to the Update method.
So start by copying that.
And pasting it at the end
like that will change the name to create.
Then will change the ESC u l to insert instead of update using named place holders as before.
We don't need to bind the idees value as this is a new rijkaard so we can delete this line.
Finally let's change the comment.
Like that.
Now you might be thinking that we've repeated ourselves a bit here by having this method and the update
method we based it on.
And you could if you wanted to have one method for example cold save that would insert are updater rijkaard
depending on whether it had an I.D. are not for example.
However if you do that you'll find that you're filling the method with lots of IF statements for the
parts that differ between insert and update.
For example the Eskew L binding the idees value are nuts and it can get messy.
I think it's clearer to have two similar methods instead.
One more thing we need to do before we test this is to create the database connection object which we're
passing into this new method here.
So let's do that.
As in the other scripts.
Let's give that a try.
First let's check the validation.
And that works read displaying the farm and if we enter a value that's displayed as well.
If I enter a valid values and submit the form we get an article not found a message looking at the U
R L we have being redirected to the show article page.
But there's no idae in the query string.
After we've inserted in you rijkaard with this method.
Here is where we read.
I read it to the new article but simply executing this esky well.
Walter signed the idea of the new record to the object far as we have to do that manually.
We can get that by calling the last insert idees method on the PDA object.
This returns the idae assigned by the database to the new rijkaard.
So instead of returning from the method here let's change this to an if statement and if this returns
true will assign the idea of this object to the new idea from the database and return true.
So now if I enter valid data in the form and submit it were redirected to the newly created rijkaard.
Finally.
Now that we've converted all our code pages to use the new article and database classes we no longer
need these two files so we can safely delete them.