WEBVTT

00:00.080 --> 00:00.530
Okay guys.

00:00.530 --> 00:03.680
So welcome in the second project of the course.

00:03.680 --> 00:10.310
First, let me quickly show you around the project, and then we're gonna move on to things that we

00:10.310 --> 00:11.720
are about to learn.

00:11.750 --> 00:14.330
That's the main page of our blog.

00:14.330 --> 00:20.450
As you can see, we're gonna build a simple blog where you can read the posts and if you are signed

00:20.480 --> 00:24.830
in and that's your blog post, you can also edit or delete it.

00:24.830 --> 00:29.090
And also people can comment, but for that they need an account.

00:29.120 --> 00:34.160
There is also a separate dashboard panel for users that have permissions.

00:34.160 --> 00:38.240
They can see the stats, the recent posts, recent comments.

00:38.270 --> 00:41.510
They can also manage the blog posts.

00:42.050 --> 00:45.050
Now if you want to comment on the posts.

00:45.050 --> 00:48.680
As I've said, you need to be signed in first.

00:49.010 --> 00:50.390
So that's the project.

00:50.420 --> 00:54.560
Now let's move on to the things that we're going to introduce and learn.

00:55.490 --> 01:04.190
So in this project, we're gonna be moving on from just using functions into the object oriented programming.

01:04.190 --> 01:08.900
And we are going to divide this project into two parts.

01:08.960 --> 01:16.340
One part is the framework part where we're going to put all the reusable logic that is not really unique

01:16.340 --> 01:22.310
to this project, but can generally help us build web applications with PHP.

01:22.700 --> 01:28.640
And we try to do that already in the previous project, but everything was kind of mixed.

01:28.670 --> 01:37.400
Now we will be using objects and classes, so it should be much easier to create some reusable code,

01:37.400 --> 01:44.840
for example, to do the error handling for all the database related stuff and for view handling which

01:44.840 --> 01:46.490
is generating the output.

01:46.520 --> 01:54.680
Obviously, the router will also have its own separate logic independent from this specific app, and

01:54.680 --> 02:03.770
then some concepts will be introduced on how you can more efficiently organize your application code.

02:03.770 --> 02:12.510
So the code that is much more specific to your current application and project done generally to making

02:12.510 --> 02:13.500
websites.

02:13.500 --> 02:16.830
This would be our application specific code.

02:16.830 --> 02:25.050
We're going to be introducing some of the concepts that modern PHP frameworks use, like controller

02:25.050 --> 02:33.990
classes, the model classes for database interactions, the views middleware, so everything that runs

02:33.990 --> 02:41.970
before the request is handled, and service classes for more application bespoke logic that doesn't

02:41.970 --> 02:43.710
fit anything else.

02:44.700 --> 02:49.590
Now as you see, the list of things we are about to learn is rather significant.

02:49.590 --> 02:56.640
Starting from separating the common logic, the framework logic and the application logic.

02:56.880 --> 03:02.790
So we're going to have two folders the app folder, which application specific logic, and then the

03:02.790 --> 03:06.990
core folder which will contain some generic code.

03:06.990 --> 03:11.550
For example for database handling or for routing.

03:13.020 --> 03:19.620
Then we are using object oriented programming, which means we are generally trying to use classes.

03:19.650 --> 03:24.240
This also means introducing namespaces to our code.

03:24.270 --> 03:28.110
We're going to have more database abstractions.

03:28.110 --> 03:35.550
Base database class that is going to use PDR, and then model classes with basic Crud operations.

03:35.550 --> 03:43.770
So create, read, update and delete for a specific table to simplify working with typical database

03:43.800 --> 03:45.000
operations.

03:45.030 --> 03:52.050
Then instead of the root handler we're going to introduce controller classes that have methods also

03:52.050 --> 03:53.700
called actions.

03:54.000 --> 03:59.220
So an example of a such controller class for post.

04:01.110 --> 04:06.990
This is something that you are also going to see a lot in modern PHP frameworks.

04:06.990 --> 04:14.190
Then the middleware that's the code that can run before a root or after a root.

04:14.220 --> 04:21.480
Typically you might use it to check if the user is actually signed in if he has the rights to access

04:21.480 --> 04:21.900
the page.

04:21.900 --> 04:25.590
And that's exactly what we're going to be using Middlewares for.

04:25.620 --> 04:28.260
Next up, service classes.

04:28.260 --> 04:32.010
That would be some generic reusable business logic.

04:32.010 --> 04:39.330
For example, everything that relates to authentication, signing in users, checking if the user is

04:39.330 --> 04:42.270
signed in and has a session created.

04:42.270 --> 04:43.770
This kind of things.

04:43.800 --> 04:50.550
Dependency injection container a simple version of it, but I'm going to talk in more detail once we

04:50.550 --> 04:51.600
get to it.

04:51.600 --> 04:54.690
And then we're going to improve the view logic.

04:54.720 --> 05:01.410
We're going to have separate layouts that you can choose for every view, because your page might have

05:01.410 --> 05:09.150
different needs if that's a main blog page or maybe a dashboard or admin panel, you need some different

05:09.150 --> 05:12.810
menu options and layouts need to be different.

05:12.810 --> 05:18.780
Then we're going to introduce a smart way to provide some global variables to our views, so we don't

05:18.780 --> 05:22.380
have to fetch the user from the session every single time.

05:22.380 --> 05:29.580
You can simply access a user variable to figure out if the user is signed in or not inside the view.

05:29.610 --> 05:32.220
Let me show you a quick example.

05:32.910 --> 05:40.500
For example, in this main layout, it's enough to just check the user variable and we know if he is

05:40.500 --> 05:43.470
signed in and also what role does he have?

05:44.130 --> 05:47.580
We can also improve the way we pass data to templates.

05:47.610 --> 05:53.250
Every single item you pass through the data array will now be available as a variable.

05:53.280 --> 05:54.750
Next up security.

05:54.780 --> 05:56.400
A super important part.

05:56.400 --> 06:02.910
So we're gonna have user authentication essentially user accounts and ability to sign in with email

06:02.910 --> 06:04.320
and password.

06:04.470 --> 06:07.290
Then user authorization.

06:07.290 --> 06:14.160
So we're gonna be checking if users are authorized to perform certain operations.

06:14.160 --> 06:22.950
For example, whether you are authorized to write blog posts or are you authorized to edit this particular

06:22.950 --> 06:25.170
blog post or delete it?

06:25.200 --> 06:26.950
Things of this nature.

06:27.670 --> 06:30.100
Then we're gonna be logging to a file.

06:30.100 --> 06:32.890
So everything that happens inside the app.

06:32.890 --> 06:40.300
So far, we've been logging to the console of the running PHP process, and we should be really keeping

06:40.300 --> 06:42.640
those logs for later inspection.

06:42.640 --> 06:47.890
That's why we're going to be putting all of the things that had happened to a file.

06:47.920 --> 06:53.890
Then I'm gonna introduce the composer and auto loading concepts.

06:53.920 --> 06:57.190
We're going to be creating more CLI scripts.

06:57.190 --> 07:05.560
And also finally, we're going to learn how to improve error handling and create custom error pages

07:05.560 --> 07:12.850
for different kinds of errors like page not found, you are not authorized or generic server errors.

07:13.060 --> 07:20.500
A lot of things are awaiting us, and we're gonna learn a ton of things that will most definitely make

07:20.500 --> 07:29.200
you ready to use all the modern frameworks and tools that are available when you consider yourself a

07:29.410 --> 07:30.700
PHP developer.
