Phalcon interview questions

Phalcon interview questions

Phalcon interview questions and answers

Download Phalcon interview questions PDF

Phalcon interview questions

Phalcon uses a powerful and fast templating engine called Volt.
Volt is an ultra-fast and designer-friendly templating language written in C for PHP. It provides you a set of helpers to write views in an easy way. Volt is highly integrated with other components of Phalcon, just as you can use it as a stand-alone component in your applications.
source (https://docs.phalconphp.com/en/3.0.0/reference/volt.html)

Also, Read Best Laravel 5 interview questions

The root folder of Phalcon Php contains files and directories

  • App
    • Config
    • Controllers
    • Library
    • Migrations
    • Models
    • Views
  • Cache
  • Public
    • Css
    • files
    • img
    • js
    • temp
  • .htaccess
  • .htaccess
  • .htrouter.php
  • index.html

Read 40+ Core PHP Interview Questions

Below is the list of Application Events in Phalcon.

Event NameTriggered
bootExecuted when the application handles its first request
beforeStartModuleBefore initialize a module, only when modules are registered
afterStartModuleAfter initializing a module, only when modules are registered
beforeHandleRequestBefore execute the dispatch loop
afterHandleRequestAfter execute the dispatch loop

Single Module Application: Single MVC applications consist of one module only. Namespaces can be used but are not necessary.

Multi-Module Application: A multi-module application uses the same document root for more than one module.

If a service container (DI) is available for Volt, you can use the services by only accessing the name of the service in the template:


{# Inject the 'flash' service #}
<div id="messages">{{ flash.output() }}</div>

{# Inject the 'security' service #}


The setVar() method is used to pass data from the controller to view template in Phalcon.


Usage:- $this->view->setVar("username", $user->username);

Zephir – Ze(nd Engine) Ph(p) I(nt)r(mediate) – is a high-level language that eases the creation and maintainability of extensions for PHP. Zephir extensions are exported to C code that can be compiled and optimized by major C compilers such as gcc/clang/vc++. Functionality is exposed to the PHP language

source (https://github.com/phalcon/zephir)

Phalcon offers the object-oriented classes, necessary to implement the Model, View, Controller architecture (often referred to as MVC) in your application. This design pattern is widely used by other web frameworks and desktop applications.

MVC benefits include:

  • Isolation of business logic from the user interface and the database layer.
  • Making it clear where different types of code belong for easier maintenance.

If you decide to use MVC, every request to your application resources will be managed by the MVC architecture. Phalcon classes are written in C language, offering a high-performance approach to this pattern in a PHP based application.

Phalcon CSRF tokens use sessions, so if you increase your session timeout it will automatically increase the token time as well.

Phalcon uses PDO_ to connect to databases. The following database engines are supported:

  • Phalcon\Db\Adapter\Pdo\Mysql : Mysql
  • Phalcon\Db\Adapter\Pdo\Postgresql : Postgresql
  • Phalcon\Db\Adapter\Pdo\Sqlite : SQLite

Phalcon session component provides object-oriented wrappers to access session data.
Below is usage guide to Read, Write and Delete sessions in Phalcon

Writing or Creating session in Phalcon

 $this->session->set("user-name", "Michael");

Reading or Retrieving session in Phalcon

 $this->session->get("user-name");

Deleting or Removing session in Phalcon

  $this->session->remove("user-name");

find(),findFirst(),query(),findFirstBy(),count(),save(),delete()
Read More

PHQL stands for Phalcon Query Language, PHQL is a high-level, object-oriented SQL dialect that allows writing queries using a standardized SQL-like language. PHQL is implemented as a parser (written in C) that translates syntax in that of the target RDBMS.

Phalcon uses an independent module “Phalcon\Validation” for validating users requests. This component can be used to implement validation rules on data objects that do not belong to a model or collection.
The loosely-coupled design of this component allows you to create your own validators along with the ones provided by the framework.
The following example shows basic usage of validations in Phalcon :

<?php

use Phalcon\Forms\Element\Text;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\StringLength;

$name = new Text(
    "name"
);

$name->addValidator(
    new PresenceOf(
        [
            "message" => "The name is required",
        ]
    )
);

$name->addValidator(
    new StringLength(
        [
            "min"            => 10,
            "messageMinimum" => "The name is too short",
        ]
    )
);

$form->add($name);

Routing in Phalcon Framework is managed by its Router component. Router components allow you to
define routes that are mapped to controllers or handlers that should receive the request from your application.A router simply parses a URI to determine this information. The router has two modes: MVC mode and match-only mode. The first mode is ideal for working with MVC applications.