In the index and article pages we're getting a list of all the articles and getting an individual article
using this get article function here as we're writing code related to an article.
It would make more sense to make this cold part of an article class.
So let's create a new class in the classes folder called Article P. H.
P in here will add the P E P opening tag and the class name.
In our index page we're using this called to get all the articles from the database.
So let's copy this.
And in our new class let's create a method to do this.
Let's add a new method called get RL.
And as this method won't be acting upon an individual article object this needs to be a static method.
Then let's paste the code we just copied from the index page.
Instead of assigning these results to a variable we'll return them from the method like that.
For this to work we need a connection to the database so let's pass this into the method as an argument.
And finally let's add a p-h Peacock comment block for the method and also for the class.
Then in our index page let's require this new class file and then we can replace this code with a call
to the new method passing in the database connection object.
And when we open the index page in the browser we see the list of articles as before.
In the individual article script we're calling the get article function which is here in the includes
article file.
This function gets an article based on an idea.
Let's add a method to our new article class that does this.
Let's start by copying this entire function.
Including the comment block and pasting it in the article class.
Let's add the visibility of public and this is again a static method as it's not being called on an
instance of this class.
Let's also change the name of the method to get by eidy like that.
In our individual article script.
We're going to use the method in the new article class now so we can replace this line with a require
of the new class instead.
Then we can change this function call to call the new class method instead.
Then in the browser if we view an individual article this works as before.