Giter Site home page Giter Site logo

cyrialize / traversy-mvc Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 27 KB

Code written while following along with the Object Oriented PHP & MVC course on Udemy. This code is for sections 1 to 4. Sections 5 and 6 are in a different repository. https://www.udemy.com/course/object-oriented-php-mvc/

PHP 100.00%
php mvc oop

traversy-mvc's Introduction

What is this?

This repository contains the code created while following along with the Object Oriented PHP & MVC course by Traversy Media.

The code isn't exactly the same as what is presented within the course. There are some minor differences, like spacing, curly brackets, style, etc. See below for more details.

This code is for sections 1 - 4. Section 5 - 6 can be found here. In sections 5 and 6 you create an application on top of the framework. I wanted to keep the framework separate.

Why do this course?

Creating your own framework is a great way (in my opinion) to understand the inner workings of frameworks and to become familiar with PHP.

It also opens you up to the possibilities of not using a framework when working on a project.

Differences between this code and the course

  • I went through this course on Linux instead of Windows, so my setup was different (see the section below on how to set it up for Linux)
  • For config.php I created a config.ini file to load in sensitive things and added config.ini to the .gitignore

Minor Differences

Most of these are due to personal preference

  • Anytime there were single quotes with strings being appended, I switched them to double quotes and string interpolation
  • Used [] instead of array()
  • Used command line MySQL and MySQL Workbench instead of PHPMyAdmin

Setting it up on Linux

Since .htaccess files are used for routing, you cannot use PHP's built in server, e.g. php -S localhost:8000.

Instead, you'll have to set up a virtual host on apache. This will also fix the following errors:

  • Internal Server 500 showing up on the web page
  • AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. showing up on the error log

You'll also need to change the line 7 in public/.htaccess to include a forward slash before index.php

  • RewriteRule ^(.+)$ /index.php?url=$1 [QSA,L]

The following steps were completed on Ubuntu 20.04:

  • Install PHP for apache: sudo apt install libapache2-mod-php7.4
    • If you run into an error that looks like this:
    The following packages have unmet dependencies:
    libapache2-mod-php7.4 : Depends: php7.4-common (= 7.4.3-4ubuntu2.4) but 7.4.9-1+ubuntu18.04.1+deb.sury.org+1 is to be installed
    E: Unable to correct problems, you have held broken packages.
    
    • You can fix it with: sudo apt remove php7.4-common and attempting to re-install
  • Turn on the php mod for apache: sudo a2enmod php7.4
  • Turn on rewrites for apache: sudo a2enmod rewrite
  • Open an editor for etc/apache2/apache2.conf
  • Add the following:
Listen 8000
<VirtualHost *:8000>
    DocumentRoot /home/mxjonny/Code/traversymvc/
    <Directory /home/mxjonny/Code/traversymvc/>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
  • You can replace 8000 with whatever port your prefer for localhost
  • Replace the path that comes after DocumentRoot and Directory with the path to your code
  • Run sudo systemctl stop apache2 to stop apache
  • Run sudo systemctl start apache2 to start apache
  • Run sudo systemctl restart apache2 to restart apache

Solving Issues

could not find driver on Lesson 23 'The Database Class - Part 1'

You're probably missing the mysql package for PHP.

Install it for your version of PHP: sudo apt install php7.4-mysql.

Then restart apache.

Other Resources

I'm a big fan of the No Framework Tutorial by Patrick Louys.

TODOs

These todos are additional things I've thought about adding to the code once I've completed the course.

I may also split this code out and make my own version of the code.

  • Add doc blocks to all of the functions
  • Add type checking to functions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.