Okay guys.
So welcome in the second project of the course.
First, let me quickly show you around the project, and then we're gonna move on to things that we
are about to learn.
That's the main page of our blog.
As you can see, we're gonna build a simple blog where you can read the posts and if you are signed
in and that's your blog post, you can also edit or delete it.
And also people can comment, but for that they need an account.
There is also a separate dashboard panel for users that have permissions.
They can see the stats, the recent posts, recent comments.
They can also manage the blog posts.
Now if you want to comment on the posts.
As I've said, you need to be signed in first.
So that's the project.
Now let's move on to the things that we're going to introduce and learn.
So in this project, we're gonna be moving on from just using functions into the object oriented programming.
And we are going to divide this project into two parts.
One part is the framework part where we're going to put all the reusable logic that is not really unique
to this project, but can generally help us build web applications with PHP.
And we try to do that already in the previous project, but everything was kind of mixed.
Now we will be using objects and classes, so it should be much easier to create some reusable code,
for example, to do the error handling for all the database related stuff and for view handling which
is generating the output.
Obviously, the router will also have its own separate logic independent from this specific app, and
then some concepts will be introduced on how you can more efficiently organize your application code.
So the code that is much more specific to your current application and project done generally to making
websites.
This would be our application specific code.
We're going to be introducing some of the concepts that modern PHP frameworks use, like controller
classes, the model classes for database interactions, the views middleware, so everything that runs
before the request is handled, and service classes for more application bespoke logic that doesn't
fit anything else.
Now as you see, the list of things we are about to learn is rather significant.
Starting from separating the common logic, the framework logic and the application logic.
So we're going to have two folders the app folder, which application specific logic, and then the
core folder which will contain some generic code.
For example for database handling or for routing.
Then we are using object oriented programming, which means we are generally trying to use classes.
This also means introducing namespaces to our code.
We're going to have more database abstractions.
Base database class that is going to use PDR, and then model classes with basic Crud operations.
So create, read, update and delete for a specific table to simplify working with typical database
operations.
Then instead of the root handler we're going to introduce controller classes that have methods also
called actions.
So an example of a such controller class for post.
This is something that you are also going to see a lot in modern PHP frameworks.
Then the middleware that's the code that can run before a root or after a root.
Typically you might use it to check if the user is actually signed in if he has the rights to access
the page.
And that's exactly what we're going to be using Middlewares for.
Next up, service classes.
That would be some generic reusable business logic.
For example, everything that relates to authentication, signing in users, checking if the user is
signed in and has a session created.
This kind of things.
Dependency injection container a simple version of it, but I'm going to talk in more detail once we
get to it.
And then we're going to improve the view logic.
We're going to have separate layouts that you can choose for every view, because your page might have
different needs if that's a main blog page or maybe a dashboard or admin panel, you need some different
menu options and layouts need to be different.
Then we're going to introduce a smart way to provide some global variables to our views, so we don't
have to fetch the user from the session every single time.
You can simply access a user variable to figure out if the user is signed in or not inside the view.
Let me show you a quick example.
For example, in this main layout, it's enough to just check the user variable and we know if he is
signed in and also what role does he have?
We can also improve the way we pass data to templates.
Every single item you pass through the data array will now be available as a variable.
Next up security.
A super important part.
So we're gonna have user authentication essentially user accounts and ability to sign in with email
and password.
Then user authorization.
So we're gonna be checking if users are authorized to perform certain operations.
For example, whether you are authorized to write blog posts or are you authorized to edit this particular
blog post or delete it?
Things of this nature.
Then we're gonna be logging to a file.
So everything that happens inside the app.
So far, we've been logging to the console of the running PHP process, and we should be really keeping
those logs for later inspection.
That's why we're going to be putting all of the things that had happened to a file.
Then I'm gonna introduce the composer and auto loading concepts.
We're going to be creating more CLI scripts.
And also finally, we're going to learn how to improve error handling and create custom error pages
for different kinds of errors like page not found, you are not authorized or generic server errors.
A lot of things are awaiting us, and we're gonna learn a ton of things that will most definitely make
you ready to use all the modern frameworks and tools that are available when you consider yourself a
PHP developer.