This is a step-by-step tutorial, which shows you how to set up and use the Adventure PHP Framework (short: APF).
First, you need a PHP-capable server. As local test server under windows you might have a look at XAMPP page. It contains an installation of all important server components like Apache, PHP, MySQL, etc. Depending on your setup, you need to adjust the paths used in this tutorial. On LINUX/UNIX boxes you might install the PHP libraries using your favorite package manager.
Under Downloads you can always find the latest version. Writing this tutorial, version 3.0 was the latest.
There, the following packages are available:
For this tutorial we will use the "framework code release", which you can download now.
You need to understand the structure of the folders first. This tutorial expects the document root (the folder which is being opened when you visit http://localhost/ in your browser) under /xampp/htdocs.
The APF is designed delivering a website using only one file. This file (e.g. index.php) is called "bootstrap" file. We create the folder /xampp/htdocs for it. Here you can further place public accessible files (e.g. CSS, JS, pictures).
For security reasons the APF files should not be accessible for the public, otherwise the public might read your configuration files. The best way would be, placing the package above the document root. If that's not possible (e.g. on a simple web space without control of the document root) please proceed with chapter 4.2 where a special security rule is being created. Otherwise follow the description in chapter 4.1.
Because the document root is placed at /xampp/htdocs, we will create /xampp/APF/ where the files downloaded before should be extracted.
You should now have the following directory structure:
/xampp/APF/
core/
modules/
tools/
...
htdocs/
You can now proceed with chapter 5.
If you intend to install the APF within an area that is accessible from the public you need to ensure that the files are protected adequately.
Please create /xampp/htdocs/APF/ and extract the downloaded package in here.
You should now have the following directory structure:
/xampp/htdocs/APF/
core/
modules/
tools/
...
In order to secure the APF files please create a .htaccess file within /xampp/htdocs/APF with the following content:
# Apache <=2.2
Order allow,deny
deny from all
# Apache >=2.4
Require all denied
Let's explain the folders first:
Please now create the /xampp/htdocs/index.php file. We will now write a simple "hello world!" application in order to explain the base functions of the APF.
We now need to create the folder /APF/helloworld that contains the template - helloworld.html. The template should be added the following content:
Hello World!
In order to generate the output please adapt the previously created index.php as follows
// Include bootstrap file for the folder configured in chapter 4.1
include('../APF/core/bootstrap.php');
// Include bootstrap file for the folder configured in chapter 4.2
include('./APF/core/bootstrap.php');
use APF\core\singleton\Singleton;
use APF\core\frontcontroller\FrontController;
// create the front controller
$fC = Singleton::getInstance(FrontController::class);
// start request processing and send result to the client
echo $fC->start('APF\helloworld', 'helloworld');
First of all, the bootstrap.php is included that executes the basis configuration of the framework. After that, the front controller is created and started with the initial template. The first parameter of the start() method is the namespace (=path to the template) and the second names the template file. Template files are always passed without their file extension within the APF since the *.html extension is appended by convention automatically. Last but not least, the content is sent to the client via echo.
The exact function of the front controller can be read about on the Front controller page.
In order to see the result please call
http://localhost/index.php
within your browser. There you should see Hello World! now.
Now the base functionality of the APF should be clear. In order to get to know the many other functions, you should read some more tutorials. We suggest the My first website tutorial as a next step.
This article was exclusively written for adventure-php-framework.org.
Ralf Schubert, an enthusiastic APF developer likes the framework giving the chance to easily develop reusable gui elements (aka. widgets). This is one of the reasons, why he had chosen the APF to be his application development framework of choice.
To support beginners, he wrote this article to give a brief introduction into the framework and to ease the first steps using the APF.
In order to provide a state-of-the-art web experience and to continuously improve our services we are using cookies. By using this web page you agree to the use of cookies. For more information, please refer to our Privacy policy.