300+ TOP Phalcon Interview Questions [UPDATED]

  1. 1. What Is Phalcon ?

    Phalcon is an open source, full stack framework for PHP written as a C-extension, optimized for high performance. You don’t need to learn or use the C language, since the functionality is exposed as PHP classes ready for you to use.

  2. 2. Explain Dependency Injection In Phalcon ?

    PhalconDi is a component implementing Dependency Injection and Location of services and it’s itself a container for them.

    Since Phalcon is highly decoupled, PhalconDi is essential to integrate the different components of the framework. The developer can also use this component to inject dependencies and manage global instances of the different classes used in the application.

    Basically, this component implements the Inversion of Control pattern. Applying this, the objects do not receive their dependencies using setters or constructors, but requesting a service dependency injector. This reduces the overall complexity since there is only one way to get the required dependencies within a component.

    Additionally, this pattern increases testability in the code, thus making it less prone to errors.


  3. PHP Interview Questions

  4. 3. List Basic Features Provided By Phalcon ?

    First of all Phalcon is not like any other php framework because it’s a php extension written in C. Php extension are .so files like extension=phalcon.so

    Since it’s a php extension it’s always loaded if the extension is enabled in php.ini file, even with nothing build. And this going to make this perform fast.

    The framework have no defined directory structure, so you can build your application in different pattern like multi-module, HMVC etc

  5. 4. Explain Directory Structure Of Phalcon Framework?

    • app/config holds configuration files that are used for the app. I use YAML for all static configuration that I don’t want to keep in the database, usually registering them as services in the bootstrap.
    • app/utilities is where I put helper classes for my app. It has a dedicated namespace (“Utilities”) which makes all of them easy to use.

  6. PHP Tutorial

  7. 5. How To Register Namespaces, Prefixes, Directories Or Classes In Phalcon ?

    Registering Namespaces:

    If you’re organizing your code using namespaces, or using external libraries which do, the registerNamespaces() method provides the autoloading mechanism. It takes an associative array; the keys are namespace prefixes and their values are directories where the classes are located in. The namespace separator will be replaced by the directory separator when the loader tries to find the classes. Always remember to add a trailing slash at the end of the paths.

    Registering Directories:

    The third option is to register directories, in which classes could be found. This option is not recommended in terms of performance, since Phalcon will need to perform a significant number of file stats on each folder, looking for the file with the same name as the class. It’s important to register the directories in relevance order. Remember always add a trailing slash at the end of the paths.

    Registering Classes:

    The last option is to register the class name and its path. This autoloader can be very useful when the folder convention of the project does not allow for easy retrieval of the file using the path and the class name. This is the fastest method of autoloading. However the more your application grows, the more classes/files need to be added to this autoloader, which will effectively make maintenance of the class list very cumbersome and it is not recommended.

    Additional file extensions:

    Some autoloading strategies such as “prefixes”, “namespaces” or “directories” automatically append the “php” extension at the end of the checked file. If you are using additional extensions you could set it with the method “setExtensions”.


  8. Zend Interview Questions

  9. 6. Explain Routing In Phalcon?

    The router component allows to define routes that are mapped to the controllers or handlers that should receive the request. A router parses a URI as per the information received.

    Every router in the web application has two modes:

    • MVC mode
    • Match-only mode

    The first mode is ideal for working with MVC applications. Following is the syntax to define a route in Phalcon.

    $router = new Router();  
    // Define a route 

    $router->add( 
       “”, 
       [ 
          “controller” => “”, 
          “action”     => “”, 
       ] 
    );

  10. 7. How Can You Add Validations In Phalcon?

    PhalconValidation is an independent validation component that validates an arbitrary set of data. This component can be used to implement validation rules on data objects that do not belong to a model or collection.

    The following example shows its basic usage:

    use PhalconValidation;
    use PhalconValidationValidatorEmail;
    use PhalconValidationValidatorPresenceOf;
    $validation = new Validation();
    $validation->add(
        “name”,
        new PresenceOf(
            [
                “message” => “The name is required”,
            ]
        )
    );
    $validation->add(
        “email”,
        new PresenceOf(
            [
                “message” => “The e-mail is required”,
            ]
        )
    );
    $validation->add(
        “email”,
        new Email(
            [
                “message” => “The e-mail is not valid”,
            ]
        )
    );
    $messages = $validation->validate($_POST);
    if (count($messages)) {
        foreach ($messages as $message) {
            echo $message, “
    “;
        }
    }


  11. Zend Tutorial
    AJAX Interview Questions

  12. 8. List Some Database Related Functions In Phalcon?

    Phalcon encapsulates the specific details of each database engine in dialects. Those provide common functions and SQL generator to the adapters.

    Class—Description

    PhalconDbDialectMysql–SQL specific dialect for MySQL database system

    PhalconDbDialectPostgresql–SQL specific dialect for PostgreSQL database system

    PhalconDbDialectSqlite–SQL specific dialect for SQLite database system

  13. 9. How To Read , Write And Delete Sessions In Phalcon?

    Starting the Session:
    Some applications are session-intensive, almost any action that performs requires access to session data. There are others who access session data casually. Thanks to the service container, we can ensure that the session is accessed only when it’s clearly needed:

    $di->setShared(
        “session”,
        function () {
            $session = new Session();

            $session->start();

            return $session;
        }
    );

    Storing/Retrieving data in Session: 
    From a controller, a view or any other component that extends PhalconDiInjectable you can access the session service and store items and retrieve them in the following way:

    {
        public function indexAction()
        {
            // Set a session variable
            $this->session->set(“user-name”, “Michael”);
        }

        public function welcomeAction()
        {
            // Check if the variable is defined
            if ($this->session->has(“user-name”)) {
                // Retrieve its value
                $name = $this->session->get(“user-name”);
            }
        }

    }

    Removing/Destroying Sessions: 
    It’s also possible remove specific variables or destroy the whole session:

    use PhalconMvcController;

    class UserController extends Controller
    {
        public function removeAction()
        {
            // Remove a session variable
            $this->session->remove(“user-name”);
        }

        public function logoutAction()
        {
            // Destroy the whole session
            $this->session->destroy();
        }
    }


  14. PHP and Jquery Interview Questions

  15. 10. How To Increase Csrf Timeout In Phalcon ?

    tokens use sessions, so if you increate your session it will increase the totken time aswell.


  16. AJAX Tutorial

  17. 11. Explain Mvc In Phalcon ?

    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 of this pattern in a PHP based application.

    Models:
    A model represents the information (data) of the application and the rules to manipulate that data. Models are primarily used for managing the rules of interaction with a corresponding database table. In most cases, each table in your database will correspond to one model in your application. The bulk of your application’s business logic will be concentrated in the models. Learn more

    Views:
    Views represent the user interface of your application. Views are often HTML files with embedded PHP code that perform tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application. Learn more

    Controllers:
    The controllers provide the “flow” between models and views. Controllers are responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation. 


  18. MVC Framework Interview Questions

  19. 12. What Is Zephir In Phalcon ?

    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


  20. PHP Interview Questions

  21. 13. How To Pass Data From Controller To View In Phalcon?

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

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


  22. PHP and Jquery Tutorial

  23. 14. Which Template Engine Phalcon Use ?

    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.

  24. 15. How Can You Inject Services Into A Volt Template?

    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 #}

    {{ flash.output() }}

    {# Inject the ‘security’ service #}


  25. CakePHP Interview Questions

  26. 16. Explain Odm In Phalcon?

    ODM (Object-Document Mapper) offers a CRUD functionality, events, validations among other services in Phalcon.


  27. MVC Framework Tutorial

  28. 17. Single Or Multi Module Applications In Phalcon?

    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.


  29. Spring MVC Framework Interview Questions

  30. 18. List Various Type Of Application Events In Phalcon?

    Below are the list of Application Events in Phalcon:

    • Event Name–Triggered
    • boot–Executed when the application handles its first request
    • beforeStartModule–Before initialize a module, only when modules are registered
    • afterStartModule–After initialize a module, only when modules are registered
    • beforeHandleRequest–Before execute the dispatch loop
    • afterHandleRequest– After execute the dispatch loop

  31. Zend Interview Questions