Skip to content

Commit fe048bf

Browse files
authored
Merge pull request #9 from urls-framework/v2.0.1
V2.0.1
2 parents 9e8bf9f + b521177 commit fe048bf

34 files changed

+1245
-23
lines changed

docs/classes/methods/path.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Creates a new path.
1212
| $file | - | String/Array/Object: Urls | :heavy_check_mark: | The file path and name you want to use as a template or an array containing one string element you want to directly output or a Urls object to compare a sub-path. |
1313
| $end | False | Bool | :x: | True if this is the end of the path. If there is more after this point, it will be seen as not matching and will result in a 404 error. |
1414
| $cs | NULL | Bool | :x: | Whether this path is case sensitive or not. If NULL, the default defined in `URLS::$cs` will be assumed. |
15-
| $vars | NULL | Array | :x: | An array of variables to pass on to the included page. |
15+
| $vars | NULL | All | :x: | A variable to pass on to the included page. The variable is added to the end of the array `Urls::$vars`. |
1616
## Examples
1717
```PHP
1818
<?php
@@ -29,7 +29,7 @@ $blog = new Urls;
2929
$urls->path('posts/', 'posts.php', true, false);
3030

3131
$urls = new Urls;
32-
$urls->path('blog/', 'blog-home.php', true, false, array("Hello, ", "World!"));
32+
$urls->path('blog/', 'blog-home.php', true, false, "Hello, World!");
3333
$urls->path('blog/', ["This is my blog!"], true, false);
3434
$urls->path('blog/', Urls::echo("This is my blog!"), true, false);
3535
$urls->path('blog/', $blog, false, false); // Note: $end should always be false if $file is type object or else, $blog will not be called

guides/MANUAL_INSTALL.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
?>
1313
```
1414
3. Create a `.htaccess` file in the base directory and fill it with the following (fill in the blanks):
15-
```
15+
```ApacheConf
1616
# --URLS BEGIN--
1717
# The following lines between \"--URLS BEGIN--\" and \"--URLS END--\" are
1818
# automatically generated by the URLS framework. These lines should
@@ -23,14 +23,15 @@
2323
RewriteRule ^(the name of your settings file regex encoded)$ - [L]
2424
# --URLS ADD_COND BEGIN--
2525
# --URLS ADD_COND END--
26-
RewriteCond %{REQUEST_FILENAME} !-f
27-
RewriteCond %{REQUEST_FILENAME} !-d
26+
RewriteCond %{REQUEST_FILENAME} !-d [OR]
27+
RewriteCond %{REQUEST_FILENAME} !-f [OR]
28+
RewriteCond %{REQUEST_FILENAME} \.php$
2829
RewriteRule . (the name of your settings file regex encoded) [L]
2930
RewriteRule ^$ (the base directory followed by the settings file name) [L]
3031
# --URLS END--
3132
```
3233
Here is a complete example:
33-
```
34+
```ApacheConf
3435
# --URLS BEGIN--
3536
# The following lines between "--URLS BEGIN--" and "--URLS END--" are
3637
# automatically generated by the URLS framework. These lines should
@@ -42,8 +43,9 @@
4243
RewriteRule ^settings\.php$ - [L]
4344
# --URLS ADD_COND BEGIN--
4445
# --URLS ADD_COND END--
45-
RewriteCond %{REQUEST_FILENAME} !-f
46-
RewriteCond %{REQUEST_FILENAME} !-d
46+
RewriteCond %{REQUEST_FILENAME} !-d [OR]
47+
RewriteCond %{REQUEST_FILENAME} !-f [OR]
48+
RewriteCond %{REQUEST_FILENAME} \.php$
4749
RewriteRule . /blog/setting.php [L]
4850
RewriteRule ^$ /blog/settings.php [L]
4951
# --URLS END--

guides/tutorial/COMPLETE_TUTORIAL.md

+51
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,56 @@ This guide will walk you through a complete implementaion of URLS. You will be m
1212
2. [Getting Started with URLS](getting_started.md)
1313
3. [Templates](templates.md)
1414
4. [Static Files](static_files.md)
15+
5. [More Pages](pages.md)
16+
6. [Nesting Pages (part 1)](nesting_p1.md)
17+
7. [Nesting Pages (part 2)](nesting_p2.md)
18+
8. [Nesting Pages (part 3)](nesting_p3.md)
19+
9. [Variable Paths](variable.md)
20+
10. [HTTP Errors (part 1)](errors_p1.md)
21+
11. [HTTP Errors (part 2)](errors_p2.md)
22+
12. [HTTP Errors (part 3)](errors_p3.md)
23+
13. [Case Sensitivity](cs.md)
24+
14. [Redirects](redirects.md)
25+
15. [Passing Variables](vars.md)
26+
16. [Deploying](deploy.md)
27+
17. [Conclusion](conclusion.md)
28+
29+
## Project Structure
30+
```
31+
└── (base directory)/
32+
├── errors/
33+
│ ├── 404.php
34+
│ ├── 500.php
35+
│ └── contributors_500.php
36+
├── includes/
37+
│ ├── footer.inc.php
38+
│ └── header.inc.php
39+
├── static/
40+
│ └── style.css
41+
├── templates/
42+
│ ├── about.php
43+
│ ├── Another-Friend.php
44+
│ ├── authors.php
45+
│ ├── contributors.php
46+
│ ├── errors.php
47+
│ ├── home.php
48+
│ ├── Me.php
49+
│ ├── My-Friend.php
50+
│ ├── posts.php
51+
│ └── vars.php
52+
├── urls/
53+
│ ├── LICENSE
54+
│ ├── update.php
55+
│ └── Urls.php
56+
├── .htaccess
57+
├── author_settings.php
58+
└── settings.php
59+
```
60+
## Project Images
61+
|<picture><img alt="Output" src="assets/home_tutorial.png"></picture>|<picture><img alt="Output" src="assets/about_page.png"></picture>|
62+
|--------------------------------------------------------------------|--------------------------------------------------------------------|
63+
|<picture><img alt="Output" src="assets/posts_tutorial.png"></picture>|<picture><img alt="Output" src="assets/post_1_tutorial.png"></picture>|
64+
|<picture><img alt="Output" src="assets/authors_tutorial.png"></picture>|<picture><img alt="Output" src="assets/404.png"></picture>|
65+
1566
___
1667
[Next: Project Setup](setup.md)

guides/tutorial/assets/404.png

19.3 KB
Loading

guides/tutorial/assets/about_page.png

24.2 KB
Loading
29.6 KB
Loading
19.5 KB
Loading
22 KB
Loading

guides/tutorial/assets/p5_404.png

21.8 KB
Loading
60.8 KB
Loading
105 KB
Loading

guides/tutorial/assets/vars.png

26.1 KB
Loading

guides/tutorial/conclusion.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Conclusion
2+
This is finally the end of this tutorial. You should now have a solid understanding of the URLS Framework. The complete project files for this tutorial can be found [here](/guides/tutorial/files). The final project structure should look like:
3+
```
4+
└── (base directory)/
5+
├── errors/
6+
│ ├── 404.php
7+
│ ├── 500.php
8+
│ └── contributors_500.php
9+
├── includes/
10+
│ ├── footer.inc.php
11+
│ └── header.inc.php
12+
├── static/
13+
│ └── style.css
14+
├── templates/
15+
│ ├── about.php
16+
│ ├── Another-Friend.php
17+
│ ├── authors.php
18+
│ ├── contributors.php
19+
│ ├── errors.php
20+
│ ├── home.php
21+
│ ├── Me.php
22+
│ ├── My-Friend.php
23+
│ ├── posts.php
24+
│ └── vars.php
25+
├── urls/
26+
│ ├── LICENSE
27+
│ ├── update.php
28+
│ └── Urls.php
29+
├── .htaccess
30+
├── author_settings.php
31+
└── settings.php
32+
```
33+
While this tutorial covered most topics, there is still a lot to learn about URLS. Now that you've completed this tutorial, the best way to learn more is to visit the [documentation](/DOCS.md).
34+
Happy coding! :)
35+
___
36+
[Previous: Deploying](deploy.md)

guides/tutorial/cs.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Case Sensitivity
2+
By default, URLS is case sensitive. However, there may be times where you don't want a path or even the project to be case sensitive. This section will cover how to make something not case sensitive.
3+
## Project Level Case Sensitivity
4+
Project level case sensitivity is the easiest to implement. Typically, you want to make the entire project case sensitive so we are going to keep it case sensitive.
5+
1. Set `Urls::$cs = true` under `Urls::$defaultErrors` in `settings.php`. The file should now look like:
6+
```PHP
7+
<?php
8+
/*
9+
URLS framework url config file.
10+
11+
Add your paths here:
12+
ex. $urls->path('blog/', 'blog-home.php', true);
13+
*/
14+
include 'urls/Urls.php';
15+
Urls::$base = '/';
16+
Urls::$defaultErrors[404] = "errors/404.php";
17+
Urls::$cs = true;
18+
19+
$contributors = new Urls;
20+
$contributors->errors[404] = "errors/contributors_404.php";
21+
$contributors->path('/', 'templates/contributors.php', true);
22+
$contributors->path('Me', 'templates/Me.php', true);
23+
$contributors->path('My-Friend', 'templates/My-Friend.php', true);
24+
$contributors->path('Another-Friend', 'templates/Another-Friend.php', true);
25+
26+
$urls = new Urls;
27+
$urls->path('/', 'templates/home.php', true);
28+
$urls->path('about/', 'templates/about.php', true);
29+
$urls->path('about/authors/', 'authors_settings.php');
30+
$urls->path('about/contributors/', $contributors);
31+
$urls->path('posts/', 'templates/posts.php', true);
32+
$urls->path('posts/<post>/', 'templates/posts.php', true);
33+
34+
$urls->exe();
35+
36+
?>
37+
```
38+
2. That's it! If you want to make the project not case sensitive, simpily set `Urls::$cs` to `false`.
39+
40+
## Path Level Case Sensitivity
41+
Path level Case Sensitivity can be set on all paths and redirects (to be covered later). So far, we have only used three arguments in a path. The fourth argument is a boolean variable that sets the case sensitivity.
42+
1. Add the path `$urls->path('home/', 'templates/home.php', true, false);` to `$urls` in `settings.php`. The file should now look like:
43+
```PHP
44+
<?php
45+
/*
46+
URLS framework url config file.
47+
48+
Add your paths here:
49+
ex. $urls->path('blog/', 'blog-home.php', true);
50+
*/
51+
include 'urls/Urls.php';
52+
Urls::$base = '/';
53+
Urls::$defaultErrors[404] = "errors/404.php";
54+
Urls::$cs = true;
55+
56+
$contributors = new Urls;
57+
$contributors->errors[404] = "errors/contributors_404.php";
58+
$contributors->path('/', 'templates/contributors.php', true);
59+
$contributors->path('Me', 'templates/Me.php', true);
60+
$contributors->path('My-Friend', 'templates/My-Friend.php', true);
61+
$contributors->path('Another-Friend', 'templates/Another-Friend.php', true);
62+
63+
$urls = new Urls;
64+
$urls->path('/', 'templates/home.php', true);
65+
$urls->path('about/', 'templates/about.php', true);
66+
$urls->path('about/authors/', 'authors_settings.php');
67+
$urls->path('about/contributors/', $contributors);
68+
$urls->path('posts/', 'templates/posts.php', true);
69+
$urls->path('posts/<post>/', 'templates/posts.php', true);
70+
$urls->path('home/', 'templates/home.php', true, false);
71+
72+
$urls->exe();
73+
74+
?>
75+
```
76+
2. Now if you go to a URL like [localhost/HoMe](http://locahlost/HoMe) you should see the home page.
77+
___
78+
[Previous: HTTP Errors (part 3)](errors_p3.md)
79+
[Next: Redirects](redirects.md)

guides/tutorial/deploy.md

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Deploying
2+
The final step to building our blog is deploying it on a web server. URLS makes it really easy to deploy your site however, there are a few things that need to be changed in order for it to work on a live server.
3+
1. Make sure that your site is not in debug mode. Debug mode is off by default, however it is a good idea to manually turn it off. To do this, add `Urls::$debug = false` under `Urls::$cs` in `settings.php`. The final file should look like:
4+
```PHP
5+
<?php
6+
/*
7+
URLS framework url config file.
8+
9+
Add your paths here:
10+
ex. $urls->path('blog/', 'blog-home.php', true);
11+
*/
12+
include 'urls/Urls.php';
13+
Urls::$base = '/';
14+
Urls::$defaultErrors[404] = "errors/404.php";
15+
Urls::$cs = true;
16+
Urls::$debug = false;
17+
18+
$contributors = new Urls;
19+
$contributors->errors[404] = "errors/contributors_404.php";
20+
$contributors->path('/', 'templates/contributors.php', true);
21+
$contributors->path('Me', 'templates/Me.php', true);
22+
$contributors->path('My-Friend', 'templates/My-Friend.php', true);
23+
$contributors->path('Another-Friend', 'templates/Another-Friend.php', true);
24+
25+
$urls = new Urls;
26+
$urls->path('/', 'templates/home.php', true);
27+
$urls->path('about/', 'templates/about.php', true);
28+
$urls->path('about/authors/', 'authors_settings.php');
29+
$urls->path('about/contributors/', $contributors);
30+
$urls->path('posts/', 'templates/posts.php', true);
31+
$urls->path('posts/<post>/', 'templates/posts.php', true);
32+
$urls->path('home/', 'templates/home.php', true, false);
33+
$urls->redirect('post1/', Urls::$base.'posts/1');
34+
$urls->redirect('URLS/', 'https://github.com/urls-framework/URLS', false, 302);
35+
$urls->path('vars/', 'templates/vars.php', true, true, "This is a variable from the path");
36+
37+
$urls->exe();
38+
39+
?>
40+
```
41+
2. Next, set `Urls::$base` to the project directory you will be deploying to. If you used the public root as your base directory in development and you are deploying to the root directory on your server, then you do not need to change this.
42+
3. In `.htaccess`, change the `RewriteBase` to your new directory. Then change the path before "settings.php" in `RewriteRule . /urlsblog/settings.php [L]` and `RewriteRule ^$ /urlsblog/settings.php [L]` to your new directory. For example, if your development `.htaccess` is:
43+
```ApacheConf
44+
# --URLS BEGIN--
45+
# The following lines between "--URLS BEGIN--" and "--URLS END--" are
46+
# automatically generated by the URLS framework. These lines should
47+
# not be edited as it may result in unwanted behavior of the site. Any
48+
# edits made may be overwritten automatically.
49+
Options +FollowSymLinks
50+
RewriteEngine On
51+
RewriteBase /urlsblog/
52+
RewriteRule ^settings\.php$ - [L]
53+
# --URLS ADD_COND BEGIN--
54+
# --URLS ADD_COND END--
55+
RewriteCond %{REQUEST_FILENAME} !-d [OR]
56+
RewriteCond %{REQUEST_FILENAME} !-f [OR]
57+
RewriteCond %{REQUEST_FILENAME} \.php$
58+
RewriteRule . /urlsblog/settings.php [L]
59+
RewriteRule ^$ /urlsblog/settings.php [L]
60+
# --URLS END--
61+
```
62+
then your production `.htaccess` would be:
63+
```ApacheConf
64+
# --URLS BEGIN--
65+
# The following lines between "--URLS BEGIN--" and "--URLS END--" are
66+
# automatically generated by the URLS framework. These lines should
67+
# not be edited as it may result in unwanted behavior of the site. Any
68+
# edits made may be overwritten automatically.
69+
Options +FollowSymLinks
70+
RewriteEngine On
71+
RewriteBase /
72+
RewriteRule ^settings\.php$ - [L]
73+
# --URLS ADD_COND BEGIN--
74+
# --URLS ADD_COND END--
75+
RewriteCond %{REQUEST_FILENAME} !-d [OR]
76+
RewriteCond %{REQUEST_FILENAME} !-f [OR]
77+
RewriteCond %{REQUEST_FILENAME} \.php$
78+
RewriteRule . /settings.php [L]
79+
RewriteRule ^$ /settings.php [L]
80+
# --URLS END--
81+
```
82+
if your development directory was `/urlsblog/` and your production directory was the public root. Again, if you used the public root as your base directory in development and you are deploying to the root directory on your server, then you do not need to change this.
83+
4. Finally, upload your project files to your server. Since each host is different, I cannot show you how to do it. Contact your host to find out how to upload files.
84+
___
85+
[Previous: Passing Variables](vars.md)
86+
[Next: Conclusion](conclusion.md)

guides/tutorial/errors_p1.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# HTTP Errors (part 1)
2+
In the [last section](variable.md), if a post was not found, then the user would be redirected to [localhost/posts](http://localhost/posts). This is not the best way to handle error. A better way is to call a 404 error. Luckily, URLS helps with that.
3+
## Calling Errors
4+
1. In `posts.php` change the if statement right after the `$posts` definition to:
5+
```PHP
6+
if (isset(Urls::$access['post'])) {
7+
if (isset($posts[Urls::$access['post']])) {
8+
$pageTitle = $posts[Urls::$access['post']]['title'];
9+
} else {
10+
Urls::$self->error_404();
11+
}
12+
} else {
13+
$pageTitle = 'Posts';
14+
}
15+
```
16+
The file should now look like:
17+
```PHP
18+
<?php
19+
20+
$posts = array(
21+
'1'=>array('title'=>'Post One', 'content'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque in scelerisque nibh, et mattis nunc. Aliquam cursus placerat ex in varius. Phasellus urna elit, aliquam nec nulla ac, fringilla blandit justo. Nulla facilisi. Pellentesque non orci non urna venenatis egestas. Quisque gravida mi sed dui fermentum, eu tincidunt elit cursus. Sed lobortis ut turpis quis pretium. Phasellus accumsan tempus commodo. Proin nisi justo, mollis in faucibus ut, mattis a dolor. Ut congue mi tortor, nec pharetra tellus pretium non. Maecenas finibus, sapien in eleifend efficitur, risus magna volutpat sem, nec iaculis risus enim non tellus. Fusce lacinia odio a nibh molestie tincidunt. Aenean nec dui leo.'),
22+
'2'=>array('title'=>'Post Two', 'content'=>'Nam mattis lacus id sem vulputate, vel congue nulla consectetur. Sed euismod justo eu urna molestie efficitur. Suspendisse egestas mattis feugiat. Fusce viverra varius sem. Fusce sed sollicitudin ipsum. Sed pulvinar vulputate eros, eget lobortis mi lacinia eget. Nunc egestas id velit id pellentesque. Nam aliquam vestibulum nunc at varius. Donec mauris nisl, pretium ac tempus eget, pulvinar non elit.'),
23+
'3'=>array('title'=>'Post Three', 'content'=>'Praesent gravida suscipit hendrerit. Donec in purus hendrerit, mattis quam vel, fermentum odio. Nulla non elit molestie, tincidunt odio at, lacinia magna. Donec id elementum elit. Morbi consectetur urna arcu, dignissim dictum velit vulputate vitae. Integer sed varius lorem, a vestibulum felis. Ut tempor tortor vitae lorem posuere volutpat. Morbi consectetur neque viverra est laoreet, et faucibus turpis sagittis. In sit amet est quis enim euismod euismod. Integer sed nisi malesuada, iaculis ante vel, tempus nisl. Nulla ex risus, facilisis et ullamcorper eget, accumsan at erat. Ut vitae mollis augue, nec bibendum libero. Integer non leo eget risus euismod ornare vitae nec purus. Nam tincidunt aliquet elit.'),
24+
);
25+
26+
if (isset(Urls::$access['post'])) {
27+
if (isset($posts[Urls::$access['post']])) {
28+
$pageTitle = $posts[Urls::$access['post']]['title'];
29+
} else {
30+
Urls::$self->error_404();
31+
}
32+
} else {
33+
$pageTitle = 'Posts';
34+
}
35+
36+
include './includes/header.inc.php';
37+
38+
if (isset(Urls::$access['post']) && isset($posts[Urls::$access['post']])) {
39+
?>
40+
<h1><?php echo $posts[Urls::$access['post']]['title']; ?></h1>
41+
<p><?php echo $posts[Urls::$access['post']]['content'] ?></p>
42+
<?php
43+
} else {
44+
for ($i=0; $i < count($posts); $i++) {
45+
?>
46+
<h1><a href="<?php echo Urls::$base.'posts/'.urlencode($i + 1); ?>"><?php echo $posts[strval($i + 1)]['title']; ?></a></h1>
47+
<p><?php echo $posts[strval($i + 1)]['content'] ?></p>
48+
<?php
49+
}
50+
}
51+
52+
?>
53+
54+
<?php include './includes/footer.inc.php'; ?>
55+
```
56+
2. If you try to go to any post that does not exist like [localhost/posts/5](http://localhost/posts/5), you will get a 404 error.
57+
<picture>
58+
<img alt="Output" src="assets/p5_404.png">
59+
</picture>
60+
## Explanation
61+
This section has a couple new parts to it, the first one being the `Urls::$self` variable. This variable works like the `$this` variable. It contains the current instance of the `Urls` class. So why wouldn't you just use `$this`? The reason is because `$this` refers to the current object. While `$this` will usually work, if you are working inside another class within your file, `$this` will no longer refer the current `Urls` instance. Instead of `Urls::$self`, we could have used `end(Urls::$objects)`. This variable is an array that holds every instance of the `Urls` class called to get to this point in the order they were visited. There are other errors you can call with URLS. They are `error_404()`, `error_500()`, `error_403()`, `error_400()`, and `error_401()`. If you want to call any other errors, you have to use the `error()` function. See [error()](/docs/classes/methods/error.md) in the [documentation](/DOCS.md) for more information.
62+
___
63+
[Previous: Variable Paths](variable.md)
64+
[Next: HTTP Errors (part 2)](errors_p2.md)

0 commit comments

Comments
 (0)