-
Quick start
-
The basics
-
Helper classes
- Benchmark Class
- Cache Class
- Captcha Class
- cURL Class
- Database Class
- Date Class
- Errors Class
- FileSystem Class
- FTP Class
- Images Class
- Language Class
- Logger Class
- Number Class
- PayPal Class
- PHPMailer Class
- Plugins Class
- RestClient Class
- Security Class
- Template Class
- Text Class
- URL Class
- XML Class
- ZIP Class
Hello World
webpackages Works according to the MVC principle. That is roughly the HTML / CSS code of the PHP code are separate from each other. This applies only half to the webpackages framework. Webpackages needs PHP to output dynamic content to HTML pages. How exactly is this?
The packages folder contains 2 folders that are necessary for this example. First, the controllers
folder. This has the task of supplying the web application with data from the database (or from wherever) and storing or outputting the data, if desired. This will also invoke the so called template (HTML / CSS) and pass values that the PHP should process in the HTML script. The second folder is the views
folder. Here are our templates as well as CSS and Javascript files.
-
package
The webpackages main folder
-
controllers
Does the controller the Web application supplied with data
- welcome.class.php The controllers of the template calls and builds the representation
-
views
Contains template give the appearance that the website
- css The sample CSS folder
- js The sample JavaScript folder
-
templates
Contains the templates to display
- header.php The header file that is inserted into each template automatically at the top spot.
- footer.php The footer file in every template automatically at bottom is inserted.
- index.php The index contains the body of a page (as head and footer coming from the other two).
-
controllers
Does the controller the Web application supplied with data
welcome.class.php
The welcome.class.php would for calling index.php
look template as follows:
<?php
class welcome extends \package\core\load_functions
{
public function hello()
{
$this->template->setData(array(
'hello_world' => 'Hello World'
));
$this->template->display('template/index.php');
}
}
?>
It should be noted that your class inherits the class load_functions. This includes the utility classes and save you the template display and transmit data.
Analysis of the code
What happens in the welcome class ?! Well it is actually quite simple. The welcome class is inherited as the first load_functions class. This contains all auxiliary classes which can also be used after inheritance. Next, the welcome class defines the method to be called. This is in our case the hello method. In this, we are linking to our template / index.php
template with the help class template
.
$this->template->display('template/index.php');
We also passed to the template nor a variable
$this->template->setData(array(
'hello_world' => 'Hello World'
));
This variable is hello_world
and has the content Hello World
. The helper class template
now received the variable to the template, and then retrieves the template from it to represent. In the background, he adds before calling the header.php
template and the footer.php
template to the index.php
to.
Template analysis
In the following step, we analyze the template index.php
to find out such as the hello_world
variable can be output in the template. The index.php
looks like this:
index.php
<body>
<p><?php echo $hello_world; ?></p>
</body>
As you can see, that was hello_world
variable, which we at the helper class template
delivered in a PHP variable had $hello_world
converted. Thus we could spend easily these in the template. This works also with arrays, objects, integer, boolean and other types that are available in PHP. Even whole class could be delivered. This webpackages is clean, fast and reliable.
Here we should also briefly the header.php
and footer.php
look. These included the head and foot area of the template.
header.php
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World Example</title>
</head>
footer.php
</html>
In the your user's Web Edition, all would put together are issued and ultimately look like.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World Example</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>
The method hello()
is a standard way when no other than parameter is passed.
Classes control call
Webpackages at least 2 GET required parameters to control the call of your classes.
$_GET['c']
This calls the class to (welcome in our example, but without the .class.php)$_GET['m']
This searches in the class method (in our case, hello)
A sample call might look like this: https://www.example.de/index.php?c=welcome&m=hello
Want if I were the class foo calls and in overview the method, it would look like this: https://www.example.de/index.php?c=foo&m=overview
If mod_rewrite
is installed and enabled, the GET statement can also look like this: https://www.example.de/foo/overview.html