📄️ Workopia Project Intro
Now it's time to start our project. I said this in the course intro, but I want to say it again. What I really want to focus on here is the underlying framework of our application. I don't mean an existing open-source framework like Laravel or Symphony. I mean the core of our application. We're not focusing on the design or the front-end all that much. It's not a React course or something like that. We're doing a lot of backend stuff. So it may not seem like a lot of functionality, because it really isn't, however to build the infrastructure or the framework for this project to sit on is a lot of work. That's why my plan is to build this project again in Laravel but since Laravel gives us that framework, we can add a lot of new features in that course.
📄️ UI Theme Files
I have created the HTML and CSS for this project and included the files in the download for this lesson. Download the theme folder to your machine.
📄️ Folder Setup
Now we want to create our project folder. If you are on Windows and using Laragon, create a folder in C:\laragon\www called workopia. If you are using XAMPP, create it in your htdocs folder.
📄️ Home View & Changing the Document Root
Our project will have a controller->view structure. Meaning all of our logic for a specific route will go into the controller and then the HTML will go into the view for that specific route. Let's start off by creating a view for the homepage.
📄️ Git Setup
This is technically optional, but I would highly reccomend that you use Git version control. Git allows you to save and version your work. Git is something every developer needs to at least know the basics of. We will create a Git repository now and make a commit. You can continue to make commits and save your code when you see fit.
📄️ Partials & Load Functions
We saw in the last lesson how we can include a view. The home view has everything in it including the ` and tags. This is not ideal. We want to be able to reuse the and ` tags. Otherwise, we will have to copy and paste them into every view. One solution is to break them up into partials.
📄️ inspect Debug Helper
There will be many times where you want to inspect the value of a variable or object. We will create two functions in our helpers.php file to help us do that.
📄️ Creating a Basic Router
So as we have it right now, there is a public/index.php file that loads a view. We want to be able to load different views based on the URL that is being requested. We also need a place for logic such as working with the database. That logic will go into a controller. This is a common pattern in web development. The controller will be responsible for loading the view and passing data to it.
📄️ create-views
Now we will create and load the views for the routes that we created in the last lesson.
📄️ Separate Routing Files
Now that we have a working router and 404 handling, let's clean up our code a bit and take the routing logic out of the public/index.php file.
📄️ Router Class & Methods
So we have an extremely simple procedural router right now that loads a specific controller when a route is hit. However, we need more than that. We need a way to pass the HTTP method into the controller. If we just want to go to a route, that would be a GET request, but if we are submitting a form to create data, that would be a POST request. We also want to be able to send DELETE requests and also PUT requests for updating data.