We've changed the index and individual article pages to use pto and our new article class next.
Let's change the edit article page first.
We need to use the article class to get the article record being edited instead of this function.
Just like in the article script.
So first let's change the database require to load the Database class instead and will also additionally
require the article class.
Then we get the database connection and call the method.
Then if the article is found we need to access its properties as an object instead of as an array.
However instead of assigning the objects properties to variables like this let's just use them directly.
These variables are used in the form to display values in the farm controls so we can get rid of these
for variable assignments.
And then in the farm replace these variables with the equivalent properties of the article object.
Let's just check that that works and it does displaying the values in the farm directly from the article
object's properties.
We can remove this empty block now by negating the article variable and removing the ELSE next if the
farm is submitted.
We're getting the values from the farm into these variables.
We just got rid of these variables above though.
So instead that's assigned the values coming from the farm to the article object's properties.
Then when we validate the article we'll pass these values in to the validate article function like that.
If the values are valid we then update the rijkaard in the database.
Let's add a method to our article class to do this.
Instead we'll add a new method called Update which is a public method and it's not static because it
acts on an instance of the class.
Let's add the esky well including all the named parameters will prepare the statement for which we need
the database connection so that's passed that as an argument to the method.
Next we need to bind values to the place holders in the ESC you out we'll bind the values of the object's
properties which we can access using the special this variable and were binding the idea as an integer
and the title and content as strings.
When you have several parameters in the esky Well this is where named parameters and paedos way of binding
values to them with a separate method call for each one is clearer.
Then my ESC U L.
I's method the published at field can be empty so we need to insert null.
If it is so let's add an if statement and if it is empty will bind NULL which has its own data type
constants and if not will bind the value of the property.
Then we execute the statement and as the execute method returns true are false depending on whether
it worked or not will return its value directly.
Finally we need to add a p p duck comment like that.
Then in the edit article page we can replace this code.
With a call to the new method we just added and we can get rid of this Else block too
in the redirect we need to replace the idees variable with the article object property like that.
Let's give that a try.
If I edit this article and change the content.
I can click save the changes are saved and we redirected back to the article page.
If I enter an invalid value
and submit the form the values we typed in I read displayed so the farm still works too.
But now using the article object instead of individual variables.