Phalcon Interview Questions & Answers

5 avg. rating (100% score) - 1 votes

Phalcon Interview Questions & Answers

Embarking on job search is like preparing to climb a mountain. This is the toughest task every candidate experience. Are you frequent job searcher on various sites? So, why looking for other sites, Just log on to www.wisdomjobs.com for better prospects. Phalcon is a PHP web framework based on the model view-controller pattern. It is loosely coupled framework means it allows its objects to be treated like glue components based on the needs of application. Phalcon does not impose a particular file structure for application development. You have a wide scope in this field to work as PHP developer, web application developer, developer, phalcon developer, senior PHP developer, PHP software developer, full stack developer etc. So, find your path by looking into the given listed phalcon job interview questions and answers.

Phalcon Interview Questions

Phalcon Interview Questions
    1. Question 1. What Is Phalcon ?

      Answer :

      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. Question 2. Explain Dependency Injection In Phalcon ?

      Answer :

      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. Question 3. List Basic Features Provided By Phalcon ?

      Answer :

      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

    4. Question 4. Explain Directory Structure Of Phalcon Framework?

      Answer :

      • 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.

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

      Answer :

      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”.

    6. Question 6. Explain Routing In Phalcon?

      Answer :

      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"     => "", 
         ] 
      );

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

      Answer :

      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:

      <?php
      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, "<br>";
          }
      }

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

      Answer :

      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

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

      Answer :

      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:

      <?php

      use PhalconSessionAdapterFiles as Session;

      // Start the session the first time when some component request the session service
      $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:

      <?php

      use PhalconMvcController;

      class UserController extends Controller
      {
          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:

      <?php
      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();
          }
      }

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

      Answer :

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

    11. Question 11. Explain Mvc In Phalcon ?

      Answer :

      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. 

    12. Question 12. What Is Zephir In Phalcon ?

      Answer :

      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

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

      Answer :

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

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

    14. Question 14. Which Template Engine Phalcon Use ?

      Answer :

      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.

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

      Answer :

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

    16. Question 16. Explain Odm In Phalcon?

      Answer :

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

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

      Answer :

      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.

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

      Answer :

      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

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PHP7 Tutorial