What is Phalcon?
Phalcon is an open source, high-performance PHP framework. It written as a C-extension, optimized for high performance. It is based on Module View Controller (MVC) pattern. Phalcon also is loosely coupled, allowing you to use its objects as glue components based on the needs of your application.
What is zephir in Phalcon?
Zephir stands for Ze(nd Engine) Ph(p) I(nt)r(mediate) . It is a high-level language. It is used for creation and maintainability of extensions for PHP. It exported to C code that can be compiled and optimized by major C compilers such as gcc/clang/vc++.
What are the basic features of Phalcon?
Low overhead: It is low memory consumption and CPU compared to traditional frameworks
MVC & HMVC: its include Modules, components, models, views and controllers. Phalcon provides the lowest overhead for MVC-based applications
Dependency Injection: Dependency Injection and Location of services and it’s itself a container for them.
Rest: In this case, you can use either a micro or full stack application to meet your goal. In addition, a powerful set of HTTP helpers.
Autoloader: It provides the auto loading mechanism of PHP classes following PSR-4.
Router: Phalcon\Mvc\Router provides advanced routing capabilities.
Can you explain MVC in Phalcon?
Phalcon offers the object-oriented classes, necessary to implement the Model, View, Controller architecture in application. This design pattern is widely used by other web frameworks and desktop applications.
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
Views: It 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.
Controllers: It provide the “flow” between models and views. It is 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.
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
Can you define ORM?
ORM (Object Relational Mapping) is provided by Phalcon allowing you to manipulate database records as classes and objects. MySQL, PostgreSQL and SQLite are supported out of the box.
Can you explain i18n?
i18n = Internationalization: i, then 18 letters, then n. Internationalization is the process (or the concept of the process) to make an application “international”; that is, make it able to support virtually any language or local setting on Earth.
The component Phalcon\Translate aids in creating multilingual applications. Applications using this component, display content in different languages, based on the user’s chosen language supported by the application.
Can you define Volt in Phalcon?
Volt is a Template engine of Phalcon.Volt is an ultra-fast and designer friendly templating language written in Zephir/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.
Can you define PHQL in Phalcon?
In Phalcon, PHQL stands for Phalcon Query Language. It is a high-level SQL that standardize SQL queries for the database system. . PHQL is implemented as a parser (written in C) that translates syntax in that of the target RDBMS. To achieve the highest performance possible, Phalcon provides a parser that uses the same technology as SQLite. This technology provides a small in-memory parser with a very low memory footprint that is also thread-safe.
What is Transactions in Phalcon?
In Phalcon, when a process performs multiple database operations, it might be important that each step is completed successfully so that data integrity can be maintained. Transactions offer the ability to ensure that all database operations have been executed successfully before the data is committed to the database.
What are the 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.
PhalconDbDialectMysql:SQL specific dialect for MySQL database system
PhalconDbDialectPostgresql:SQL specific dialect for PostgreSQL database system
PhalconDbDialectSqlite:SQL specific dialect for SQLite database system
Which protocol is used to encrypt the password in Phalcon?
In Phalcon, md5, base64 and sh1 protocol is used to encrypt the password.
Can you explain Phalcon Forms?
It handles creation and maintenance of forms in the web application. Now, as we have designed a basic web-app before we would be adding signup form.
Designing Signup form
Change the index.phtml viewfile, add the signup page link as a controller.
app/views/index/index.phtml
What are the different types of application events in phalcon?
Application Events are:
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
Explain how can we access to backend in Phalcon?
Backend is provided by logging services for application. We can login to different backend using different adapters. It offers transaction logging, configuration options, different formats and filters.
What are the different type of HTTP methods?
There is various different type of HTTP methods:
GET: It is used to retrieve and search data.
POST: It is used to add data.
PUT: It is used to update data.
DELETE: It is used to delete data.
Can you explain Cookie?
Cookie is a small text file stored by browser on user system. Cookies were designed to be a reliable mechanism for websites to remember stateful information or to record the user’s browsing activity.
Phalcon\Http\Response\Cookies is the directory where cookies are stored. Cookie management helps in storing cookies under the above directory during the request execution and is sent automatically at the end of the request.
How can we read, write and delete sessions in Phalcon?
In Phalcon, we can read, write and delete sessions by using following code:
Creating session: $this->session->set (“user-name”, “Michael”);
Reading or Retrieving session: $this->session->get (“user-name”);
Deleting or Removing session: $this->session->remove(“user-name”);
What are some of the most prominent features of Phalcon?
It is a full stack open source framework.
A user needs quite less amount of code to take advantage of several components.
It can be used to create an independent framework as required. For example, if we just need Phalcon’s Cache component, we can use it in any application written either in pure PHP or using a framework.
For a developer having knowledge of Model-View-Controller (MVC) and Object- Relational Modeling (ORM), working with Phalcon is like a cakewalk.
Can you explain Phalcon Class Autoloader?
Loader is a class found under Phalcon\Loader directory. This class consists of some pre-defined rules according to rules it loads class automatically. It also handles error such as if a class does not exist but it is called in any part of program then special handler is called for handling. In Loader if a class is added according to its need in program, performance is increased as only specific file is included. This technique is known as lazy initialization.
Phalcon\Loader have 4 methods to implement auto load classes:
- Registering Namespaces
- Registering Directories
- Registering Classes
- Registering Files
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”.
Can you explain Phalcon Security?
It provides the common security tasks to the developers such as:
Password Hashing: This technique where password is stored in the encrypted form in the database. If the password is stored in the plain text format then any intruder that has the access to the database can easily view the passwords.
CSRF: Cross-Site Request Forgery protection (CSRF) protection is against the form elements such as in user registration or adding comments are vulnerable to this attack. CSRF is created to prevent the form values from being sent outside our application. To fix this, we generate a random nonce (token) in each form.
What are the Pros of Phalcon?
- High Performance
- Fully Featured
- Application Logic
- Flexible Architecture
- Easy using
- Lightweight Framework