Creating a “Hello World!” Application with Phalcon Framework PHP

application with Phalcon Framework | In this tutorial we will try to create a “Hello World” with Phalcon Framework PHP. Before using phalcon you have to install phalcon .dll in xampp (Installing Phalcon Framework PHP on Windows).

Create a folder and some files as follows:


Open the Phalcon_HelloWorld/.htaccess file and enter the source code below:

RewriteEngine on RewriteRule ^$ public_html/ [L] RewriteRule (.*) public_html/$1 [L]
All requests to the application will be rewritten to the public_html/ directory making it the document root. This step ensures that the system’s internal folders remain hidden from public view and eliminates a security threat to this vulnerabilities.

Open the second file Phalcon_HelloWorld/public_html/.htaccess

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*) index.php?_url=/$1 [QSA,L]
Then we will create a bootsrap file. This file is very important as it acts as the base of the application giving you all the control.



try {

//Register an autoloader
$loader = new PhalconLoader();

//Create a DI
$di = new PhalconDIFactoryDefault();

//Setup the view component
$di->set('view', function(){
    $view = new PhalconMvcView();
    return $view;

//Setup a base URI so that all generated URIs include the "tutorial" folder
$di->set('url', function(){
    $url = new PhalconMvcUrl();
    return $url;

//Handle the request
$application = new PhalconMvcApplication($di);

echo $application->handle()->getContent();

} catch(PhalconException $e) {
echo “PhalconException: “, $e->getMessage();
Creating a controller by default Phalcon will look for a controller named “Index”. This is the starting point when no controller or action is requested in the request. Create a new file named IndexController.php in the folder Phalcon_HelloWorld/app/controllers/IndexController.php


class IndexController extends PhalconMvcController

public function indexAction()
    echo "<h1>Hello World!</h1>";

The controller class must end in “Controller” and the actions on the controller must end in “Action”. If you have finished following all the tutorials above, the folder arrangement will look like this:


Now let’s see in the browser, if it is correct it will look like this http://localhost:8080/Phalcon_HelloWorld/


Congratulations, you have finished learning the basics of the phalcon framework 😀