Access to the new article page is restricted to logged in users only.
We don't even display the link to the page.
If we're not logged in links to edit and delete are shown however and we haven't restricted access to
these just yet.
Before we do that let's look at how our site is structured at the moment all the pages are in the same
folder in the root directory of the site for most visitors.
We just want the index page and the individual article page.
If we log in we want to be able to access the other pages to edit create and delete articles.
So let's create an admin section for those users.
First let's create a folder in the root kalid admin.
We need an index page in here so let's copy the index page from the root.
Without changing anything.
Let's see what happens when we go to the admin folder in a browser.
We get an error saying the init dot p s p script wasn't found.
This is because the path we're passing to the require line here is a relative path.
In other words it's relative to the current file.
This works for pages in the root as the includes folder is at the same level.
However we can't do the same indice script as it's in the admin subdirectory to fix it.
We can add two dots to the start of the path like this.
Two dots in a path like this mean go to the parent folder of the one where this script is.
So now this require line will go up to the root directory and then into the includes folder to the init
duck p s p file
before we try this.
Let's change the next line to.
Which is also loading a file in the includes folder and also where we're loading the hates to email
header
and the footer.
So now in the browser when we look at the admin folder the error about not finding the file in the includes
folder has gone which means it's loading the files correctly but now we're presented with another error.
This time the script is trying to load the classes databased up p p file.
Classes are required in the artle loader which is in the init script here.
We've got the same problem.
It's trying to load a file relative to the admin folder but the classes folder isn't in the admin folder.
It's one level up.
Let's try adding the two dots to require in the article loader like that.
And in the browser.
This fixes it.
We can see the index page in the admin folder with no errors.
However if I go back to the index folder in the root.
Now this is broken as it's trying to load the database class file from the parent directory of where
this file is instead of at the same level which it did before we changed the autoloader.
Remember when you include efile.
It says there that file was part of the script that was including it.
Instead we want to always require class files relative to where this init script is in the includes
folder.
To do this first P HP has a predefined constants that we can use this D.
I.
Our constants contains the directory including the full path of a script file.
Then the D A our name our dear name function will return the part of the parent folder of a given path.
For example if this is the full path of the init doppie HP file the d r constant will contain this the
directory where the files
if we pass this path to the denholm function then this will return the parent directory of that directory
which in our case is the root directory of our site.
The classis folder is at the same level as the includes folder where this in its script is.
So to get to the classes folder we need to get the parent folder of where this script is which we get
by calling the cold.
We just SA which returns the parent folder of this script and inserting it before the rest of the path
to the class file.
In the browser the original index page is now fixed and if we go to the admin index
this still works too.
We don't want the admin index to be the same as the main site index though.
We want to lay it out differently with different information.
So first let's learn how to display tables of data in h t L..