Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tejasnayak25/tuskweb_php
A MVT structured backend module for php. Get your webpages online with this easy framework.
https://github.com/tejasnayak25/tuskweb_php
project
Last synced: 4 days ago
JSON representation
A MVT structured backend module for php. Get your webpages online with this easy framework.
- Host: GitHub
- URL: https://github.com/tejasnayak25/tuskweb_php
- Owner: tejasnayak25
- License: mit
- Created: 2023-01-14T13:48:23.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-15T09:42:56.000Z (almost 2 years ago)
- Last Synced: 2024-11-10T11:39:42.116Z (2 months ago)
- Topics: project
- Language: PHP
- Homepage:
- Size: 4.56 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TuskWeb_PHP
A MVT structured backend module for php. Get your webpages online with this easy framework.## Introduction
Backend programming these days for us, programmers, has been blessed with wonderful languages.
Meanwhile, PHP is being avoided due to reasons of it being uneasy. But when compared to others, hosting PHP is a lot simpler and lots of hosts are available for PHP which is not the same in case of others.So, TuskWeb - PHP is here to save your day with its pre-built modules that are going to make backend programming fun and easy.
All the cool features are now also available in PHP!So with no further ado, let's get started.
## Requirements
1) Basic knowledge of PHP.
2) A system which can run PHP.
3) A code editor like VSCode.
4) A PHP server. Eg: Xampp.## Installation
There is nothing to install here.
Just clone this repository and if you don't know how to do this, click this.Now, we are all set to get into the development stage.
## Terms
### 1) tuskweb_php
This is the framework which you will be working with.### 2) tuskweb_modules
This folder contains the core of tuskweb_php. It is highly advised not to meddle with it.### 3) workspace
This is the folder which will be containing most of your project's backend data.### 4) templates
This folder will be containing all of your templates, which are your frontend pages.### 5) static
The static folder will be containing all of your static data, i.e., your javascript and css files.### 6) media
The media folder will be containing all of the media that belongs to your site.### 7) .htaccess
These files are a part of the routing and the security system. They deny direct access to your code and keep your code safe. They also play a major role in the routing system.### 8) settings.php
This is the settings file where you will be managing your webapp settings which include baseDir and others.### 9) index.php
Something you need not worry about. This keeps your website working.##
This was all for the introduction.
Now let's build a simple website.
## Step 1: Creating a Route
Open the "urls.php" file in the workspace folder.Initially it will have something like this
```php
$urlpatterns = array(
path("/", "home", "Home"),
path("/404", "404", "404")
);
```Here the first parameter passed to the path function is the pattern of the url which you want to add, the second parameter is the name of the view(function) which you want to execute when the page is visited and the last parameter is the name of the pattern. The name is going to be used to get the pattern in other files. This will allow you to dynamically change the pattern, i.e., if you change "/" to "/home" without changing the name of the pattern, you won't have to change the urls in other files. We will learn more about this as we proceed.
For creating a new pattern, add this to the array
```php
path(pattern, view, name)
```
For example,
```php
path("/page", "page", "page")
```For paths with dynamic variables, i.e., a dynamic path, we use this
```php
path("/something/[str:varname]/page", view, name)
```
Or
```php
path("/something/[num:varname]/page", view, name)
```
This will create a new route in your website. But this alone won't work because you haven't setup your "page" view yet.## Step 2: Creating a View
Open your "views.php" file in the workspace folder.It will have something like this
```php
$views =
array(
"home" => function () {
render("/home.php", array("title" => "TuskWeb"));
},
"404" => function () {
render("/404.php", array("view" => "one", "title" => "404"));
}
);
```Here, views is the array which will be holding all of your views.
Every element of this array is a function which will be executed when the user visits the page with the url which is associated with the view.To create a view, you need to add an element to the array, whose syntax looks like
```php
"view_name" => function () {
// Here goes the executable statements which may include a render function, a redirect or statements to handle a form output.
}
```For example
```php
"page" => function () {
render("/page.php", array("title"=>"Page"));
}
```For urls with dynamic variables, we use this
```php
"page" => function ($varname) {
render("/page.php", array("data"=>$varname , "title"=>"Page"));
}
```
As for where this variable comes from, it directly comes from the url.
For example, w.r.t the above mentioned routes example, if the user visits "/something/example-page/page", then the value of the variable $varname will be "example-page"Now that your view is all set, the next step is to create the "page.php" file.
## Creating a template
Open your templates folder and create a "page.php" file.This file will hold the webpage to be loaded for the "/page" route.
It may contain something like this
```php
">
Photo by Magda Ehlers```
And now when you start up your server and visit the url you created, your webpage will be loaded.
Before we end this tutorial, a few things you need to keep in mind.
## Things To Know - Important
1) If you are ever going to change the "baseDir" setting in the "settings.php" file, make sure to change the same in the .htaccess files too.
2) If your folder isn't in the root folder of your server, then only set the "baseDir" setting, else let it be "".
3) The first parameter of the render function is the name of the template file preceded by a "/" while the second parameter is an array of the variables you want to pass to your page from the backend.
4) loadStatic and loadMedia are functions to load static files and media files respectively.
5) These are not the only things TuskWeb_PHP can do. This was just a basic tutorial. More tutorials will be uploaded in the Wiki Page.Hope you had a nice day!
### Thanks for using TuskWeb - PHP.