Created
March 27, 2017 23:31
-
-
Save CallumCarmicheal/d0d0c894513c74a48b49e2bc58185d66 to your computer and use it in GitHub Desktop.
Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Okay there are a 3 popular ways: | |
1) Have all the php and html mixed in a single file but reference others | |
this means you have like a directory called libraries, and you reference those methods with html for example: | |
```php | |
<?php | |
require_once ("libs/authentication.php"); | |
require_once ("libs/database.php"); ... etc | |
?> | |
<html> | |
.... <?=$variable?> or <?php echo $variable; ?>``` | |
So your paths are like website.com/page.php, website.com/page2.php | |
and your directory looks like | |
``` | |
Website | |
|- libs | |
| |- authentication.php | |
| |- ... | |
|- js | |
|- css | |
|- images | |
|- index.php | |
|- page.php | |
|- page2.php | |
``` | |
or | |
``` | |
Website | |
|- libs | |
| |- authentication.php | |
| |- ... | |
|- assets | |
| |- js | |
| |- css | |
| |- images | |
|- index.php | |
|- page.php | |
|- page2.php | |
``` | |
2) Same as above except your store your html/php into another | |
file. | |
This means you still have index.php, page.php, page2.php but its | |
easier to manage. | |
You may include `html/header.php`, `html/page1.php` etc or just include the `html/page1.php` file and let that include the other templated sections. | |
``` | |
Website | |
|- libs | |
| |- authentication.php | |
| |- ... | |
|- assets | |
| |- js | |
| |- css | |
| |- images | |
|- html | |
| |- templates | |
| | |- ... | |
| |- index.php | |
| |- page.php | |
| |- page2.php | |
|- .htaccess (disallow html folder access) | |
|- index.php | |
|- page.php | |
|- page2.php | |
``` | |
The requested file may look like: | |
```php | |
<?php | |
require_once ("libs/authentication.php"); | |
require_once ("libs/database.php"); ... etc | |
include ("html/index.php"); ?> | |
``` | |
The page may look like | |
```php | |
<html> | |
<?php include ("templates/header.php") ?> | |
.... <?=$variable?> or <?php echo $variable; ?>``` | |
3) Using a MVC Framework | |
This means that you have someting resembling | |
``` | |
Website | |
|- App | |
| |- Controllers | |
| | |- Authentication | |
| | | |- LoginController.php | |
| | |- IndexController.php | |
| |- Libraries | |
|- assets | |
| |- js | |
| |- css | |
| |- images | |
|- resources | |
| |- cache | |
| |- views | |
| | |- layouts | |
| | | |- default.blade.php | |
| | |- home.blade.php | |
|- .htaccess (Pass the path to mvc_app.php, allow the folder assets to be accessed) | |
|- mvc_app.php | |
``` | |
In laravel you would set the paths to each controllers, but for this example im using generic terminology. | |
You request website.com/assets/ you get website.com/assests/. | |
You request website.com/ you get IndexController.php -> index() | |
You request website.com/Authentication/Login/Login you get Authentication/LoginController.php -> Login() | |
your typical controller may look like: | |
``` | |
class IndexController extends Controller { | |
public function index() { | |
// home.blade.php | |
return view('home', ['argument' => "hello world"]); | |
} | |
} | |
``` | |
Your typical blade view looks like | |
```php | |
@extends ('layouts.default') | |
@section ('content') | |
<!-- page start--> | |
<div class="row state-overview"> | |
<div class="col-lg-3 col-sm-6"> | |
<section class="panel"> | |
<div class="symbol yellow"> | |
<i class="fa fa-user"></i> | |
</div> | |
<div class="value"> | |
<h1 class="count">{{$argument}}</h1> | |
<p>Total Users</p> | |
</div> | |
</section> | |
</div> | |
</div> | |
@endsection | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment