Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The-PHP-Practitioner-Full-Source-Code

## Setup On Your Local Machine
1. Clone the repo
2. Create the database using the mytodo.sql file by running each command separately.
3. Update config.php for your database connection
4. Run PHP's built-in webserver "php -S localhost:8000"
5. View the website at http://localhost:8000

## Add a new route
1. open app > views > routes.php and add the new route either as a GET or POST route

## Add a new view
1. Open app > views and create a new view with '.view.php' file extension
2. Open app > controllers and create a new controller
3. You can use the helper functions located in core > helpers.php to render a view or apply a redirect (see. PagesController or UsersController for examples)
5 changes: 3 additions & 2 deletions app/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public function index()
public function store()
{
App::get('database')->insert('users', [
'name' => $_POST['name']
'username' => $_POST['username'],
'password' => $_POST['password']
]);

return redirect('users');
}
}
}
7 changes: 4 additions & 3 deletions app/views/users.view.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
<h1>All Users</h1>

<?php foreach ($users as $user) : ?>
<li><?= $user->name; ?></li>
<li><?= $user->username; ?></li>
<?php endforeach; ?>

<h1>Submit Your Name</h1>
<h1>Create and account!</h1>

<form method="POST" action="/users">
<input name="name"></input>
Username:<input name="username"></input>
Password:<input name="password"></input>
<button type="submit">Submit</button>
</form>

Expand Down
12 changes: 12 additions & 0 deletions core/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ function redirect($path)
{
header("Location: /{$path}");
}

/**
* pretty print of data
*
* @param object $data
*/
function dd($data)
{
echo '<pre>';
print_r($data);
echo '</pre';
}
10 changes: 10 additions & 0 deletions mytodo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE DATABASE mytodo;

use mytodo;

CREATE TABLE users (
user_id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(155) NOT NULL,
password VARCHAR(155) NOT NULL,
PRIMARY KEY(user_id)
);