Skip to content

Commit 71c14ba

Browse files
committed
Template for initializing the PHP MVC Project application using Bootstrap v4.
0 parents  commit 71c14ba

25 files changed

+654
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor
2+
/*.lock
3+
/cache

.htaccess

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<IfModule mod_rewrite.c>
2+
RewriteEngine On
3+
4+
# redirect /index.php to /
5+
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php
6+
RewriteRule ^index.php/?(.*)$ $1 [R=301,L]
7+
8+
# process all requests through index.php, except for actually existing files
9+
RewriteCond %{REQUEST_FILENAME} !-d
10+
RewriteCond %{REQUEST_FILENAME} !-f
11+
RewriteRule ^(.*)$ index.php/$1?%{QUERY_STRING} [QSA,L]
12+
</IfModule>

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Listen for XDebug",
6+
"type": "php",
7+
"request": "launch",
8+
"port": 9000,
9+
"log": true,
10+
"cwd": "${workspaceRoot}"
11+
},
12+
{
13+
"name": "Launch currently open script",
14+
"type": "php",
15+
"request": "launch",
16+
"program": "${file}",
17+
"cwd": "${fileDirname}",
18+
"port": 9000
19+
}
20+
]
21+
}

.vscode/tasks.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "PHP Server",
8+
"type": "shell",
9+
"command": "php -S localhost:8000"
10+
}
11+
]
12+
}

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Bootstrap 4 Template
2+
3+
Template for initializing the PHP MVC Project application using Bootstrap v4.
4+
5+
The template includes a standard directory structure MVC, contains a samples of controllers and view files, and includes layout Bootstrap based.
6+
7+
Also, the template will include a filter for error handling.
8+
9+
[Demo](http://template-bootstrap4.rf.gd/)
10+
11+
## Installation
12+
13+
```
14+
git clone https://github.com/php-mvc-project/template-bootstrap4.git my-app
15+
cd my-app
16+
composer install
17+
```
18+
19+
## Requirements
20+
21+
* PHP 7.x
22+
* Composer
23+
24+
## License
25+
26+
The MIT License (MIT)
27+
28+
Copyright © 2018, [@meet-aleksey](https://github.com/meet-aleksey)

composer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "php-mvc-project/template-bootstrap4",
3+
"description": "Template for initializing the PHP MVC Project application using Bootstrap v4.",
4+
"keywords": ["php mvc project", "templates", "template", "mvc"],
5+
"license": "MIT",
6+
"type": "project",
7+
"authors": [
8+
{
9+
"name": "Meet Aleksey",
10+
"homepage": "https://github.com/meet-aleksey"
11+
}
12+
],
13+
"require": {
14+
"php-mvc-project/php-mvc": "^1.1.1",
15+
"components/jquery": "3.3.1",
16+
"twbs/bootstrap": "4.1.1"
17+
}
18+
}

content/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use this folder for static files.

content/images/php-mvc-logo.png

25.2 KB
Loading

content/styles/app.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
header {
2+
margin-bottom: 24px;
3+
}
4+
5+
.set-colon-to-labels label::after {
6+
content: ':';
7+
}

controllers/AccountController.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
// this controller shows an example of using models
3+
4+
// make sure you add the Controllers child name to the root namespace of your application
5+
namespace RootNamespaceOfYourApp\Controllers;
6+
7+
// import the base class of the controller
8+
use PhpMvc\Controller;
9+
// import class for model annotation
10+
use PhpMvc\Model;
11+
12+
// expand your class with the base controller class
13+
class AccountController extends Controller {
14+
15+
// create here action methods for the views of this controller
16+
// the action methods must have a modifier public
17+
18+
public function __construct() {
19+
// set model type for actions
20+
Model::use(array('index', 'login'), 'Login');
21+
22+
// required fields
23+
Model::required('Login', 'username');
24+
Model::required('Login', 'password');
25+
26+
// display name (for <label />) and text
27+
Model::display('Login', 'username', 'Username or Email', 'Enter any username.');
28+
Model::display('Login', 'password', 'Password', 'Enter 123.');
29+
30+
// custom validation
31+
Model::validation('Login', 'password', function($value, &$errorMessage) {
32+
if ($value != '123') {
33+
$errorMessage = 'Expected value is 123';
34+
return false;
35+
}
36+
37+
return true;
38+
});
39+
}
40+
41+
// default action
42+
// url: /account or /account/index
43+
public function index() {
44+
if (isset($this->getSession()['user'])) {
45+
// is user, redirect to home
46+
return $this->redirectToAction('index', 'home');
47+
}
48+
49+
return $this->view();
50+
}
51+
52+
// login action, only for POST requests
53+
// because the $model is required and object
54+
// url: /account/login
55+
public function login(\RootNamespaceOfYourApp\Models\Login $model) {
56+
if (!$this->getModelState()->isValid()) {
57+
// model is not valid, return login form
58+
return $this->view('index', $model);
59+
}
60+
61+
// model is valid, create session
62+
$session = $this->getSession();
63+
64+
$session['user'] = $model->username;
65+
66+
// redirect to home
67+
return $this->redirectToAction('index', 'home');
68+
}
69+
70+
// logout action
71+
// url: /account/logout
72+
public function logout() {
73+
$this->getSession()->clear();
74+
return $this->redirectToAction('index', 'home');
75+
}
76+
77+
}

0 commit comments

Comments
 (0)